Vontech615
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..
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?
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"
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?
With xcopy, the /d switch will only copy files that are newer than the ones currently in the destination.
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
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
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
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.
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.
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
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
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.
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
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
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.
Thanks again everyone and especially you becraig.