Solved

Robocopy Loop Script

Posted on 2008-10-17
6
1,087 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
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…
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 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 …

708 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