Search code examples
batch-filemoverobocopy

Robocopy - multi text files -> 1


Is it possible to merge 2 text files into 1 bigger one while doing a move? Robocopy is what I am using now but am open to other opptions.

I have a couple 'computing' servers outputting CSV-like data into individual text files. These files are then moved to a 'loading' server that bulk imports the data into a database server.

We have a lot of small files, and there is significant improvements with lesser larger files on the db import side.

Anyone have a solution? problems with

EOF's 

or

\r\n's

?


Solution

  • for /f "delims==" %%i in ('dir "\\server\share\data*.txt" /b') do (type "\\server\share\%%i">>new.txt&&echo.>>new.txt)
    


    the "delims==" is to grab the file name even if there are spaces, the %%i is for in a batch file, use %i at the command line. the "quotes" are for spaces in file names, the /b is for bare format to get rid of the other info, the echo. is to stop file2's first line from being concatenated onto file1's last line. new.txt will be in the directory you run this from.