1.

Solve : DOS copy syntax?

Answer»

It's ages since I needed to use DOS, and I'm afraid I'm a bit rusty - hope someone can help.

I have a list of files that I want to copy from ONE directory to another (about 6000 of them) - format is 003as.txt 003dhei.txt etc.

The source directory contains other files I don't wish to copy, so wildcards won't do the job, but according to copy/? 'source' is the file or files you wish to copy. I'm sure I'm missing something fairly simple here, but after hours of searching, I can't find an EXAMPLE of the syntax to copy multiple (specified) files from one directory to another.

I've tried this:
copy 003as.txt 003dhei.txt ..\otherdirectory
and all sorts of permutations with quotes, commas, etc. to no avail. I'm planning to use the list I have to BUILD a simple batch file containing that command.

Any assistance greatly appreciated.What do you call simple?
A 100 line program you can do in TWENTY minutes ?
Or a 3 line program you can get done in two days?
in the directory you are working with do this
DIR *.*
That gives everything.Now do
DIR *.* >list.txt
Now edit the file'list.txt with notepad or whatever.
Put a @ at the start of every line.
The replace every @ with 'copy ' (not the quotes, but include a space.)
Now put a %1 at the end of every line. Leav a space.
While you are doing that, delete the files you do not want copied.
You will have something like this:

copy mylov.mp3 %1
copy mylove.db %1
copy myhouse.wav %1
copy myhorse.jpg %1

save the the file as 'list.bat'

The do this
list \mybackup

the files will be copied to the \mybackup directory

You can down that maybe faster that I could.
And yes, there is some other neat cool ways to do that, but you can take days to get it right.
Your choice.



a for loop could be used to iterate each line of OUTPUT from a dir /b:

Quote

@echo off

for /f "tokens=*" %%i in ('dir /b %1') do xcopy %%i %3 /EXCLUDE:%2

place this is a batch file- and call as follows:

batfile.bat

Hope this works for you. remember to back up important data before running this, I wouldn't want to be responsible for the loss of anything important. Thanks Guys,

I used your solution, Geek-9pm - did just what I wanted. I'm still confused as to why DOS help on the copy command suggests that multiple named files can be copied at once, when this doesn't appear to be the case.

Thanks again.I believe when it says "file(s)" it means using wildcard characters- the only other option via multiple files is copying via file1+file2, which concatenates files together.


Discussion

No Comment Found