1.

Solve : merge files with COPY?

Answer»

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.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!



thank you, contrex.

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

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?Quote from: benm 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 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.




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,
BenQuote from: benm on October 11, 2007, 07:52:33 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
)

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?
with a little more experimenting, this is what i got to work

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.


Discussion

No Comment Found