Avatar of Vontech615
Vontech615
Flag 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?
Windows BatchWindows Server 2008Windows 7

Avatar of undefined
Last Comment
Vontech615

8/22/2022 - Mon
Gabriel Clifton

With xcopy, the /d switch will only copy files that are newer than the ones currently in the destination.
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
Brad Groux

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
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
SOLUTION
becraig

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
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.
Vontech615

ASKER
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
becraig

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Vontech615

ASKER
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.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
becraig

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Vontech615

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