Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
    
which version of DOS are you using? :) c'mon, give us some more info, what file types ... you're obviously looking for a way to merge those files. – Molly7244 Feb 22 '10 at 2:06
    
The post is edited – Mirage Feb 22 '10 at 2:18
2  
DOS in Windows NT-based OS's (NT, 2000, and everything since XP) really isn't DOS, it's a command shell called "cmd.exe". removed DOS tags to reflect this. – quack quixote Feb 22 '10 at 2:21
    
sorry for that , i really didn't knew that. I was thinking as DOS – Mirage Feb 22 '10 at 2:30
1  
thankfully, the last vestiges of DOS died with Windows ME. :) but no worries -- most everyone still calls the Windows command-line "DOS", so it's not wrong, just inaccurate. since real DOS is still used sometimes, i'm cleaning up the DOS tag to be just real DOS questions. – quack quixote Feb 22 '10 at 2:32

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":

Merge all CSV or TXT files in a folder in one worksheet

share|improve this answer
    
Is it possible to insert new line character after everyfile – Mirage Feb 22 '10 at 2:32
    
not with this method. – quack quixote Feb 22 '10 at 2:37
    
whats the other options. my ultimate aim is to store the contents of each text file in separate column of excel sheet. ANy ideas – Mirage Feb 22 '10 at 2:42
    
@Mirage - updated my answer according to your comment. – Molly7244 Feb 22 '10 at 2:50
    
But the problem is how can i add the endline character to each text file. Currently some of files text are in same paragrah in the merged file , so excel put it in one column. OR if i can append some endline character to all the files first and then perform merge operation – Mirage Feb 22 '10 at 3:11

To add a newLine at the end of each concatenated file, use type instead of copy, as follows:

type *.txt > newfile.txt
share|improve this answer
3  
WARNING: When you use type *.txt > newfile.txt, the text is duplicated. – Malganis Jul 19 '13 at 12:37
1  
Remove .txt from newfile and bam! There you have it. – fa wildchild Aug 29 '13 at 3:48
    
This is an awesome answer for concatenating log files or other things you will parse down the road. Specifically the fact you can do type x.log.* > merged.log without a batch file. New lines are pretty easy to deal with. – Daniel Chapman Dec 4 '13 at 16:49
    
Wow, 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 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.

share|improve this answer
2  
This is quite useful if you need to concatenate files in a particular order. – Kapep Feb 24 '12 at 2:50

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

:)

share|improve this answer
2  
A slight twist on the above: if one wants to make sure the files are concatenated alphabetically, one should use: FOR /F %%G IN ('dir /b /o *.for') DO IF NOT "%%G" == "XIT.for" copy /A MASTER.for+"%%G" && echo. >> MASTER.for – Guido Domenici Jun 26 '14 at 11:25
    
I like this. Another tweak I needed today is for for a filename header to be printed into the file to separate the input files. for %f in (*.txt) do ((echo. & echo == %f == & echo. & type %f ) >> *.txt.dat ) – Curtis Price Mar 15 at 22:01
    
I am aware that using a bash shell would probably make more sense! – Curtis Price Mar 15 at 22:05

Run the following command in the command prompt:

for %f in (*.txt) do type "%f" >> output.txt
share|improve this answer
    
That does not work as expected, all the text is duplicated in output.txt – DavidPostill Mar 25 '15 at 20:46
1  
Hint *.txt matches output.txt – DavidPostill Mar 25 '15 at 20:51

You must log in to answer this question.

protected by Community Feb 16 '15 at 4:04

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged .