windows - Any command-line or batch cmd to concatenate multiple files?

  • Mirage

    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.

  • Answers
  • blunders

    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


    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

  • nik

    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.

  • slhck

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

    type *.txt > newfile.txt

  • Related Question

    Execute multiple commands with 1 line in Windows commandline?
  • T. Stone

    How can I execute multiple commands in the Windows commandline with just a single line?

    So for example say I want to perform an SVN update and then copy all of the files to another location...

    svn update; copy *.* c:\development\copy\

    That doesn't work obviously. Is there a character or delimiter like ';' to perform something like this?

  • Related Answers
  • Phoshi

    Yes there is. It's &.

    && will execute command 2 when command 1 is complete providing it didn't fail, & will execute regardless.

  • Jujhar Singh

    At least in MS-DOS 6.22 I used to use the key Ctrl+T to get a kind of paragraph symbol. This worked just like the & mentioned by Phoshi. This will only work however, if you have doskey.exe running.

  • Scott

    In case you want to wrap the first command with an if but would still like the second command to execute regardless then then you have to wrap the if with a cmd /c as well like this:

    cmd /c if exist abc. (rd /q abc) & echo hello

    If you don't prefix the if with cmd /c then the whole command becomes part of if (which you may not want).