We help IT Professionals succeed at work.

Windows Script to copy multiple files

694 Views
Last Modified: 2014-08-08
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?
Comment
Watch Question

Gabriel CliftonNet Admin
Top Expert 2012

Commented:
With xcopy, the /d switch will only copy files that are newer than the ones currently in the destination.
Emmanuel AdebayoGlobal Windows Infrastructure Engineer - Consultant
CERTIFIED EXPERT
Top Expert 2013

Commented:
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 GrouxSenior Manager (Wintel Engineering)

Commented:
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
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
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.

Author

Commented:
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.
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
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.
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
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.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.