Combine all the lines of a text file into a single line via the Windows Command line
I wrote a command line script that makes a list of files I want to do things to such as compress, delete or email. The list would be in the following format:
7z-Compression-List.txt:
========================
file1
file2
file3
etc...
For compression, I want to combine all the lines in the list into a single line. like this:
file1, file2, file3, etc
so that I can feed all the files into the 7z command line app at the same time.
Would anyone know how I can do this? Maybe a for loop of some sort?
I ended up finding the answer in another question, here in Stack Overflow
@ECHO OFF
setlocal
(SET file-list=)
FOR /f "delims=" %%x IN (7z-Compression-List.txt) DO (
CALL SET file-list=%%file-list%%, %%x
)
SET file-list=%file-list:~1%
ECHO file-list=%file-list%
It worked beautifully. This is a modified copy of Magoo's answer, so feel free to upvote original author if you like this answer.