Home / Microsoft / Microsoft DOS / merge files with COPY
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] - (Bottom) Print
Author Topic: merge files with COPY  (Read 1215 times)
benm
Guest
« on: October 09, 2007, 01:08:42 PM »

Is there any easy way to merge many files into one file using the COPY command without naming each file?

Rather than:

copy file1.txt+file2.txt... outfile.txt

I tried:

copy *.txt outfile.txt

I am new to this so any advice is appreciated.
IP logged
contrex
Guest
« Reply #1 on: October 09, 2007, 03:10:40 PM »

At the prompt

for %a in ("*.txt") do type %a >> outfile.txt

In a batch file change % to %%

When testing, delete outfile.txt before running it a second time!



IP logged
benm
Guest
« Reply #2 on: October 09, 2007, 07:40:54 PM »

thank you, contrex.

this worked great but it seems to be doubling my file when it makes the final outfile.txt??

IP logged
benm
Guest
« Reply #3 on: October 09, 2007, 07:57:28 PM »

i think i found it.  it seems to be copying the final outfile into outfile again.  i changed the file extension on the outfile to .wrk.  this seems to work.

is it possible to apply the same logic to a CRLF dos program that i run.  rather than typing every file name?

crlf 500.txt 182 /c /s2 /ff500.txt /d
crlf 501.txt 182 /c /s2 /ff501.txt /d
...

thanks, again.

any recommended books i can read on dos to learn this?
IP logged
contrex
Guest
« Reply #4 on: October 09, 2007, 11:48:24 PM »

i think i found it.  it seems to be copying the final outfile into outfile again.

I am pretty sure - not 100% -that if it isn't there when you run the command it won't be seen by the "*.txt". You may be leaving outfile there after running the command so the next time you run it, it gets found by "*.txt".

You could either give the merged file a different extension or have it in a different folder.

Quote
is it possible to apply the same logic to a CRLF dos program that i run.  rather than typing every file name?

crlf 500.txt 182 /c /s2 /ff500.txt /d
crlf 501.txt 182 /c /s2 /ff501.txt /d

Try this

for %a in ("*.txt") do crlf %a 182 /c /s2 /ff%a /d

Quote
any recommended books i can read on dos to learn this?

I just used online guides but you could check your library.

DOS the Easy Way by Everett Murdock Ph.D. isn't too bad.




« Last Edit: October 10, 2007, 04:59:22 AM by contrex » IP logged
benm
Guest
« Reply #5 on: October 11, 2007, 07:52:33 AM »

contrex - thank you, you've been very helpful.

one last question I hope - i have been running these in a .bat file in the same folder where the files are located.  how do you i specify the folder (c:\data\etc) in the commands you've provided?

thanks,
Ben
IP logged
contrex
Guest
« Reply #6 on: October 11, 2007, 08:09:16 AM »

one last question I hope - i have been running these in a .bat file in the same folder where the files are located.  how do you i specify the folder (c:\data\etc) in the commands you've provided?

Something like this...

You put it in front of the filespec for the source files

for %a in ("C:\data\apple\orange\*.txt") do crlf %a 182 /c /s2 /ff%a /dff%a /d

I presume your crlf program will take path names in its parameters

so you'd put the path in the appropriate place

for %a in ("C:\data files\path has spaces\apple\orange\*.txt") do  crlf %%a 182 /c /s2 /"C:\data\pear\so does this one\banana\ff%%a" /d

note where I use quotes

In a batch you can open out the loop using brackets which can make it easier to visualise what's going on. You can have multiple lines.

For example

for %%a in ("C:\data files\path has spaces\apple\orange\*.txt") do (
     echo source file is %%a
     echo target file is C:\data\pear\so does this one\banana\ff%%a
     crlf %%a 182 /c /s2 /"C:\data\pear\so does this one\banana\ff%%a" /d
     )

IP logged
benm
Guest
« Reply #7 on: October 12, 2007, 07:28:12 PM »

ok, let's see if i can explain what's happening.

i tried this in the folder where the files are located

for %%a in ("*.txt") do crlf %%a 182 /c /s2 /ff%%a /d

the crlf program did work but it seems to be grabbing the first file it processed and processing it again.  so if i started with 3 input files, i get 4 output files - 3 starting with f and one starting with ff. 

next, i tried specifying where the files were located using:

for %%a in ("F:\ZIP4\DOS\*.txt") do crlf %%a 182 /c /s2 /"F:\ZIP4\DOS\ff%%a" /d

this is the message i got:  Failure in opeing working file:    :\ZIP4\DOS\ffF:\ZIP4\DOS\500.txt

any thoughts?
IP logged
benm
Guest
« Reply #8 on: October 12, 2007, 08:05:49 PM »

with a little more experimenting, this is what i got to work :P

for %%a in ("F:\ZIP4\RAW\IA\*.txt") do crlf %%a 182 /c /s2 /d
for %%a in ("F:\ZIP4\RAW\IA\*.wrk") do type %%a >> F:\ZIP4\RAW\IA\iaprod.txt
move F:\ZIP4\RAW\IA\iaprod.txt F:\ZIP4\PROD
del F:\ZIP4\RAW\IA\*.wrk

the crlf  program outputs the file with a .wrk extension.
and renaming the output file to .txt when the input files are .wrk avoids the the file being doubled up in the end.

thank you very much for your help, contrex.
IP logged
Pages: [1] - (Top) Print 
Home / Microsoft / Microsoft DOS / merge files with COPY « previous next »
 


Login with username, password and session length

Old Forum Search | Forum Rules
Copyright © 2010 Computer Hope ® All rights reserved.
Powered by SMF 2.0 RC3 | SMF © 2006–2010, Simple Machines LLC
Page created in 0.109 seconds with 18 queries.