Solved

Help with Script for copy

Posted on 2014-01-06
7
272 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 70

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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
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 70

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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Suggested Solutions

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 …
This article will show, step by step, how to integrate R code into a R Sweave document
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

737 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