Solved

Robocopy Loop Script

Posted on 2008-10-17
6
1,166 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
[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
  • 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
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!

 

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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
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 how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

691 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