Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have 50 text files in one dir.

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
    
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
show 1 more comment

3 Answers

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 merged into a single file called newfile.txt

Update

my ultimate aim is to store the contents of each text file in separate column of excel sheet.

why didn't you say that in your question? :)

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
show 3 more comments

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 a lot of files, you could loop by appending one file at a time.
Its been some time since I used DOS commands...

Also, if its binary files, you can add in the '/b' option at the end.
This is assuming you know what binary files you are working with and that they can be appended back-to-back -- else, you will get a lump of useless data.

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

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
    
WARNING: When you use type *.txt > newfile.txt, the text is duplicated. –  Malganis Jul 19 '13 at 12:37
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.