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?
LVL 1
Vontech615Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gabriel CliftonNet AdminCommented:
With xcopy, the /d switch will only copy files that are newer than the ones currently in the destination.
0
Emmanuel AdebayoGlobal Windows Infrastructure Engineer - ConsultantCommented:
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
0
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
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

becraigCommented:
I would second robocopy for this (though I love powershell :~) )

The simple reason being robocopy out of the box can simply exclude older files, copy file security etc with little or no manual lifting.

Simply create a scheduled task to run the robocopy ... e.g :
robocopy \\company-nas\elc\Shared\Sites\ \\company-nas\elc\Shared\Ops\Forms\Forms Master /XO

XO means exclude older files.
0
Vontech615Author 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.
0
Vontech615Author 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.
0
becraigCommented:
ok so robocopy to the rescue again

/purge : Deletes destination files and directories that no longer exist in the source. For additional information, see Remarks.

Read up on robocopy :
http://technet.microsoft.com/en-us/library/cc733145.aspx

It will exclude older files, copy all subdirectories in source if "/s" is used can be run in  restart mode etc......
0
Vontech615Author 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.
0
becraigCommented:
Once you specify /MIR or /s

robocopy will:

/MIR - Mirror the directory structure
/s - copy subdirectories so the destination will have the source directories.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Vontech615Author 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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.