Solved

Robocopy Loop Script

Posted on 2008-10-17
6
1,091 Views
Last Modified: 2012-05-05
Hello I need to schedule a file move operation that will take PROJECTNAME input variable from a list in a text file and loop through each project name in that list.  Depending on the project nam. it will move the files to the destination with an appropriate subfolder.  
The list of projects would look similar to this not exceeding 4 characters

PRJ1
PRJ2
PRJ3

etc..

A Manual command would look like this

robocopy \\source\share \\destination\share\PRJ1 *PRJ1* /MOVE /Z

P.S. The * is a wild card since these files are timestamped according to project and I would like to substitute PRJ1 with the variable determined by the project name provided in the list
0
Comment
Question by:gtatechinc
  • 3
  • 3
6 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 22748279
for /f %%a in (C:\Projects.txt) do start "%%" robocopy \\source\share \\destination\share\%%a %%a /move /z
0
 

Author Comment

by:gtatechinc
ID: 22748500
Hi Sir Bounty,

I created a batch file with your script above and populated projects.txt with 2 projects and modified your solution as follows:

for /f %%a in (C:\Projects.txt) do start "%%" robocopy \\source\share \\destination\share\%%a *%%a* /move /z

I popped up two shell windows simultaneously, and copied the files for the two projects simultaneoulsy.  I have thousands of files so it would be ideal if it only did one project at a time because the project list will grow to hundreds of projects and be scheduled nightly as a task.
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 125 total points
ID: 22750353
then just remove start and the "%%a"

for /f %%a in (C:\Projects.txt) do robocopy \\source\share \\destination\share\%%a *%%a* /move /z
0
3 Use Cases for Connected Systems

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

 

Author Comment

by:gtatechinc
ID: 22750369
Hi again,
I have done some modifications and it is working great now Start /Wait did the trick,  I will award you the points.  Thanks alot.  IF only I can get the logging to work properly, its seems /LOG+: only creates a log file and doesn't copy anything.  Same with >> piping it to a text file.
0
 

Author Closing Comment

by:gtatechinc
ID: 31507383
Thanks.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22756780
/Log+ will create and append to the log file.
If you want to see logging on screen as well, add /tee

Thanx for the accept - not sure why it was scored a "B" though... : \
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
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 …
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

920 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

11 Experts available now in Live!

Get 1:1 Help Now