Link to home
Start Free TrialLog in
Avatar of Vontech615
Vontech615Flag for United States of America

asked on

Windows Script to copy multiple files

Every so often our company updates forms for 65 different properties which means files get copied to 65 different directories.  I've got a script that currently just deletes the Form directory within each property directory and then copies a new directory full of forms (some new some old) to each property.

The script for copying looks like this..
for /d %%a in (\\company-nas\elc\Shared\Sites\*) do xcopy /e /y /i "\\company-nas\elc\Shared\Ops\Forms\Forms Master - ALL\" "%%a\Forms-Master-ALL" 

Open in new window


This works but I'm just curious if this is the best approach.  The next form update includes 60 updated forms (the names don't change just content within).

Is there any way to grab the 60 forms I need and just copy those without having to replace the entire directory?
Avatar of Gabriel Clifton
Gabriel Clifton
Flag of United States of America image

With xcopy, the /d switch will only copy files that are newer than the ones currently in the destination.
Avatar of Emmanuel Adebayo
Robocopy command will do the job for you

See the link below to see the Robocopy usage.

http://www.giveandtake638.com/it-system-administration/use-robocopy-movemigrate-foldersdirectoryies-one-server-another-another-location


Regards
If these sort of copies are something you'll do often, you should script it. This PowerShell script is a great example - http://gallery.technet.microsoft.com/scriptcenter/Another-PowerShell-script-8aea5f61
SOLUTION
Avatar of becraig
becraig
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Vontech615

ASKER

I can use robocopy and I'm not versed in Powershell at all, although I could tinker with it to figure it out. Gabriel's suggestion would actually work fine I think.

 The reason I wrote the originally script using the for command was due to the directories all having different names within the Sites folder.  I need something that would go through and execute the copy to all * folders.
They are telling me now that they also deleting some files on the reference directory (one to be copied with current updates).  So I would also need a second piece to this to remove deleted files in the destinations.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks becraig!

I've decided for this time around to just run my rmdir script and then the copy script.  I will probably use Robocopy instead of xcopy in the script but is there a way to create the destination directory since I'm deleting in the first part?

I looked over the syntax but didn't see this option.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Wow, that worked exactly like I wanted it too!  With the /s /MIR options I won't have to run the rmdir and won't have to copy all of them over. It updated exactly 60 forms.  Awesomesauce.

Thanks again everyone and especially you becraig.