I have 50 text files in one directory.
Is there a Windows command-line method to concatenate those files into a single file?
I am using Windows Vista.
I don't want to type the name of all files.
I have 50 text files in one directory.
Is there a Windows command-line method to concatenate those files into a single file?
I am using Windows Vista.
I don't want to type the name of all files.
I don't want to type the name of all files.
That's easy to be avoided. Open a command prompt in this folder and type the following command:
copy /b *.txt newfile.txt
Press Enter.
Now you will have all text files in this folder ordered by date ascending merged into a single file called newfile.txt.
My ultimate aim is to store the contents of each text file in a separate column of an Excel sheet.
Here's a tutorial that may help you to achieve your "ultimate aim":
copy *.txt merged.txt is a lot less painful (Windows 7).
– Daniel Chapman
Dec 04 '13 at 16:56
To add a newLine at the end of each concatenated file, use type instead of copy, as follows:
type *.txt > newfile.txt
type x.log.* > merged.log without a batch file. New lines are pretty easy to deal with.
– Daniel Chapman
Dec 04 '13 at 16:49
type has come a long way since DOS 3.3. I did not know you can use file masks. When did that happen?
– Sun
May 31 '16 at 21:24
Assuming you are talking about appending text files, the copy command can be used to append them together:
copy file1+file2+file3 targetfile
If you have many files, you could loop by appending one file at a time.
For binary files, add in the '/b' option:
copy /b file1+file2+file3 targetfile
This assumes that you know the binary files you are working with can be appended back-to-back; if not, you will get a lump of useless data.
copy https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/copy
– S Meaden
Jul 27 '19 at 19:41
Run the following command in the command prompt:
for %f in (*.txt) do type "%f" >> output.txt
output.txt
– DavidPostill
Mar 25 '15 at 20:46
The following .bat file will append all *.for files, except the one named XIT.for, to a blank file named MASTER.for
type NUL > MASTER.for
FOR %%G IN (*.for) DO IF NOT "%%G" == "XIT.for" copy /A MASTER.for+"%%G" && echo. >> MASTER.for
:)
`for %f in (*.txt) do ((echo. & echo == %f == & echo. & type %f ) >> *.txt.dat )`
– Curtis Price
Mar 15 '16 at 22:01
set n=50
for /l %i in (1,1,%n%) do type file%i.txt >> file.txt
Works on both binary & text files & ensures files concatenate consecutively (1-50).
Tested on Win 10 CMD