Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Windows Script to copy multiple files

Posted on 2014-08-08
10
Medium Priority
?
562 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?
0
Comment
Question by:Vontech615
10 Comments
 
LVL 13

Expert Comment

by:Gabriel Clifton
ID: 40248797
With xcopy, the /d switch will only copy files that are newer than the ones currently in the destination.
0
 
LVL 18

Expert Comment

by:Emmanuel Adebayo
ID: 40248832
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
 
LVL 14

Expert Comment

by:Brad Groux
ID: 40248915
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 29

Assisted Solution

by:becraig
becraig earned 2000 total points
ID: 40248968
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
 
LVL 1

Author Comment

by:Vontech615
ID: 40249047
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
 
LVL 1

Author Comment

by:Vontech615
ID: 40249051
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
 
LVL 29

Assisted Solution

by:becraig
becraig earned 2000 total points
ID: 40249055
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
 
LVL 1

Author Comment

by:Vontech615
ID: 40249335
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
 
LVL 29

Accepted Solution

by:
becraig earned 2000 total points
ID: 40249339
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
 
LVL 1

Author Comment

by:Vontech615
ID: 40249376
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

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
For anyone that has accidentally used newSID with Server 2008 R2 (like I did) and hasn't been able to get the server running again because you were unlucky (as I was) and had no backups - I was able to get things working by doing a Registry Hive rec…
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question