Question

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

?

Was it helpful?

Solution 2

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.

OTHER TIPS

try this (example):

copy /a file1.txt + file2.txt + file3.txt + file4.txt = file.txt

I think this is what you are looking for..

TYPE FILEA.TXT>FILEC.TXT
TYPE FILEB.TXT>>FILEC.TXT

Note: if you use one >, it will over-write the file each time.. If you use >> it will append.

Since you said you have a lot of little files, you can do the following as well:

FOR /F %%G IN ('DIR "D:\RESEARCH\Kent\*.TXT" /B') DO (TYPE "D:\RESEARCH\Kent\%%G">>D:\SOMEBIGFILE.TXT)
pause

Amended my answer and it works fine on a server I just checked. One "Gotcha" is where you have the SOMEBIGFILE.TXT - if that is in the same folder, it will add that too. :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top