Solved

Help with Script for copy

Posted on 2014-01-06
7
265 Views
Last Modified: 2014-01-06
I created a script that copies an entire directory from a mapped server drive to a mapped NAS drive.  The script works but I'm trying to make it more efficient if possible.  Please see code example at the bottom for structure. The important piece is that a 1 folder is copied to 65 subfolders in different Apartment property folders (ie. Apartment A, B, C, D, Etc.)  

My questions are

A.) Can robocopy create the "Pm-Master-ALL" directory?  Because I couldn't get this to work.  I had to first create the directory and then copy into it.  Otherwise it was copying all the contents but not making the directory.

B.) I tried to condense this into a 1 line script by adding a * after Sites so it looked like this...
for /d %%a in (\\company-nas\cloud-files\Shared\Sites\*) do robocopy /e "\\west-sbs\share\operations\PM Master - ALL" "%%a"

Open in new window


Well that worked but again it wasn't creating the directory.  That's when I just went in and added a line for every Apartment folder.  

CODE STRUCTURE

for /d %%a in (\\company-nas\cloud-files\Shared\Sites\Apartments-A\PM-Master-ALL) do robocopy /e "\\west-sbs\share\operations\PM Master - ALL" "%%a"

for /d %%a in (\\company-nas\cloud-files\Shared\Sites\Apartments-B\PM-Master-ALL) do robocopy /e "\\west-sbs\share\operations\PM Master - ALL" "%%a"

for /d %%a in (\\company-nas\cloud-files\Shared\Sites\Apartments-C\PM-Master-ALL) do robocopy /e "\\west-sbs\share\operations\PM Master - ALL" "%%a"

for /d %%a in (\\company-nas\cloud-files\Shared\Sites\Apartments-D\PM-Master-ALL) do robocopy /e "\\west-sbs\share\operations\PM Master - ALL" "%%a"

Open in new window

0
Comment
Question by:Vontech615
  • 3
  • 2
  • 2
7 Comments
 
LVL 12

Accepted Solution

by:
Chris earned 300 total points
ID: 39759218
If I've understood your requirements correctly, this should be as simple as adding the subfolder name to the end of the robocopy command in your first example:

for /d %%a in (\\company-nas\cloud-files\Shared\Sites\*) do robocopy /e "\\west-sbs\share\operations\PM Master - ALL" "%%a\PM Master - ALL"

Open in new window

0
 
LVL 68

Assisted Solution

by:Qlemo
Qlemo earned 200 total points
ID: 39759239
That's correct. RoboCopy expects the target folder having to receive the content of the source folder - and the source folder name is not part of that. However, the target root folder provided will be created if necessary.
0
 
LVL 1

Author Comment

by:Vontech615
ID: 39759264
Damn, that worked!  I consider myself NOT a scripting guru by any means but pretty darn good at GOOGLE and I couldn't find much on creating folders with this script.  I failed I suppose, should have come here first. Thanks again.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 12

Expert Comment

by:Chris
ID: 39759274
You're welcome :-)
0
 
LVL 1

Author Comment

by:Vontech615
ID: 39759364
I know this is closed but wanted to also ask if there was a way to included folder names with spaces within this script.  For example some of my Apartment names had spaces and normally you add quotes within windows cmd but that wasn't working.  This is for the piece within the parenthesis.
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 39759396
Probably that is because the FOR var already contains double quotes, which mix up with those used in RoboCopy:
for /d %%a in ("\\company-nas\cloud-files\Shared\Sites\*") do robocopy /e "\\west-sbs\share\operations\PM Master - ALL" "%%~a\PM Master - ALL"

Open in new window

The ~ will remove surrounding double quotes from the folder path of FOR.
0
 
LVL 1

Author Comment

by:Vontech615
ID: 39759435
That's it.  Thanks!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
A quick step-by-step overview of installing and configuring Carbonite Server Backup.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn how to count occurrences of each item in an array.

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now