
July 2nd, 2008, 09:26 PM
|
|
n00b DevH'er
|
|
Join Date: Mar 2008
Posts: 9
Time spent in forums: 2 h 5 m 56 sec
Reputation Power: 0
|
|
|
DOS Batch - Xcopy command help when dest. folder doesn't exist
I'm hoping someone can help me with some batch programming issues I'm having. I've set up a batch program that copies files with names containing a particular string from one source folder to a bunch of destination folders where they are required. The problem I am having is that I need the batch progam to have the commands to copy to every possible destination folder I may have, but when I actually run it the chances are some of the destination folders covered in the batch program won't actually exist.
At the moment when this is happening I'm asked whether I am trying to specify a folder or directory. I'm trying to figure out a way where if the destination folder doesn't exist the batch program will just skip over it and go to the next command.
Here's an example of my code:
FOR /R J:\"Source"\ %%G IN (*test1.docx) DO (xcopy "%%G" J:\"Destination1" /f /k)
FOR /R J:\"Source"\ %%G IN (*test2.docx) DO (xcopy "%%G" J:\"Destination2" /f /k)
...and so forth
So, if folder 'destination1' exists, it works fine. But assuming the 'destination2' doesn't exist it asks me to specify whether I am referring to a file or directory.
Does anyone know of some way I can make it so that if 'destination2' doesn't exist it just skips and goes onto the next line?
Thanks
|