Solved

Help with Script for copy

Posted on 2014-01-06
7
271 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VMWare Calculate number of processors 10 94
adding "ungroup sheets" to existing vbs code 5 52
BATCH to EXE Converter 2 67
Deploy restore partition 1 23
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…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

685 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