Solved

Help with Script for copy

Posted on 2014-01-06
7
268 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 69

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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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 69

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 our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

On July 14th 2015, Windows Server 2003 will become End of Support, leaving hundreds of thousands of servers around the world that still run this 12 year old operating system vulnerable and potentially out of compliance in many organisations around t…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

825 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