?
Solved

Help with Script for copy

Posted on 2014-01-06
7
Medium Priority
?
276 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 1200 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 800 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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

770 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