Discussion Locked

Concatenating files In DOS

0 helpful
10 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have a bunch of files that I need to add a single line to the beginning of. I know I can do it with "copy file1+file2 newfilename.csv". However, I want to use "file2" with a new extension as the destination. I have tried "copy header.txt+*.aqh *.csv" but I end up with one huge "header.csv" file instead of individual *.csv files.

Any scripting guru's that can help me out?

10 replies

by uch

To combine a series of files that have ".txt" extensions with several corresponding ".aqh", ".cvs" files to make new files with the same file names but with ".cvs" extensions (ie "header.txt" is combined with "file1.aqh" to form "file1.cvs", and so on).
Try using ==> COPY header.txt + *.aqh *.cvs

Good Luck.

by davidfranks78

aT THE dos PROMPT The command:

FOR %X IN (*.CSV) DO TYPE FILE.TXT >> %X

will append the contents of "file.txt" at the end of each file having the extension as ".csv"

Hope this helps.

by brianaaa12

Thats a good start, but I need the file pre-pended, not appended. Your method will put the header on the end.

Thanks,
Brian

by davidfranks78

aT THE dos PROMPT The command:

FOR %X IN (*.CSV) DO TYPE FILE.TXT >> %X

will append the contents of "file.txt" at the end of each file having the extension as ".csv"

Hope this helps.

by davidfranks78

Well, this is interesting.
Here's one more try:
If you want to use only DOS, I can think of doing doing it in 3 steps. (You need MS word also)

Step 1:

DIR *.CSV > A_FILE.BAT

This will create a file "A_FILE.BAT" with the list of all the ".csv" files.

Step 2 (part A):
Open "A_FILE.BAT" in Word and
form each line as:

COPY FILE.TXT + FILE1.CSV FILE1.XYZ
COPY FILE.TXT + FILE2.CSV FILE2.XYZ

and so on for all the .csv files...

COPY FILE.TXT + FILEn.CSV FILEn.XYZ

Step 2 (part B):

Run "A_FILE.BAT" at the DOS prompt

Step 2 (part C):

Copy all the existing .csv files somewhere safe and delete it from the current location.

Step 3:

REN *.xyz *.csv

(Step 2 may be a bit tedious, but if you know how to use macros in Word, you can make it a bit easier)

Sorry I can't think of anything better at the moment.

All the best.

by davidfranks78

Well, this is interesting.
Here's one more try:
If you want to use only DOS, I can think of doing doing it in 3 steps. (You need MS word also)

Step 1:

DIR *.CSV > A_FILE.BAT

This will create a file "A_FILE.BAT" with the list of all the ".csv" files.

Step 2 (part A):
Open "A_FILE.BAT" in Word and
form each line as:

COPY FILE.TXT + FILE1.CSV FILE1.XYZ
COPY FILE.TXT + FILE2.CSV FILE2.XYZ

and so on for all the .csv files...

COPY FILE.TXT + FILEn.CSV FILEn.XYZ
Step 2 (part B):

Run "A_FILE.BAT" at the DOS prompt

Step 2 (part C):

Copy all the existing .csv files somewhere safe and delete it from the current location.

Step 3:

REN *.xyz *.csv

(Step 2 may be a bit tedious, but if you know how to use macros in Word, you can make it a bit easier)

Sorry I can't think of anything better at the moment.

All the best.

This discussion is closed to new replies.