Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In MS DOS copying several files to one file

Tags:

dos

I am trying to take a folder that has several .csv files in it and combine all of these files and the information in them, into one file using MS DOS. Any suggestions?

like image 233
edmon Avatar asked Jul 20 '11 15:07

edmon


People also ask

How do you copy multiple files into one?

If there are multiple files you want to merge at the same time, you can select multiple files by holding down the Ctrl and selecting each file you want to merge.


3 Answers

copy *.csv new.csv

No need for /b as csv isn't a binary file type.

like image 77
marto Avatar answered Nov 01 '22 16:11

marto


copy /b file1 + file2 + file3 newfile

Each source file must be added to the copy command with a +, and the last filename listed will be where the concatenated data is copied to.

like image 22
Marc B Avatar answered Nov 01 '22 17:11

Marc B


If this is part of a batch script (.bat file) and you have a large list of files, you can use a multi-line ^, and optional /Y flag to suppresses prompting to confirm you want to overwrite an existing destination file.

REM Concatenate several files to one
COPY /Y ^
    this_is_file_1.csv + ^
    this_is_file_2.csv + ^
    this_is_file_3.csv + ^
    this_is_file_4.csv + ^
    this_is_file_5.csv + ^
    this_is_file_6.csv + ^
    this_is_file_7.csv + ^
    this_is_file_8.csv + ^
    this_is_file_9.csv ^
        output_file.csv

This is tidier than performing the command on one line.

like image 45
Mike T Avatar answered Nov 01 '22 18:11

Mike T