Link to home
Start Free TrialLog in
Avatar of lpbenergy
lpbenergyFlag for Afghanistan

asked on

VBScript "Do While"

Ok, so for starters I am VBScripting newbie.  That said, I am trying to accomplish the following;

I am trying to automate some Robocopy jobs and would like to put together a script the will spawn multiple jobs based on the contents of a text file.  The text file will contain a list of names, these names correspond to directory path. For example, the text will contain data looking as such...

Fodler1
Folder2
Folder3
etc...

The script will read the text file, line by line, spawning jobs until it reaches their are no more entries in the text file.

Source and Destination parameters will be passed via variables.  

Here is what I have conceptually in psuedoscript



Option Explicit

Dim objShell, objFSO
Dim strLog strSource, strDestination

strLog = This is the name and path of the logfile.  Each robocopy job that is spawned from this script will have a unique log file.  The log file name should be the 'Folder1.log, Folder2.Log, etc..  corresponding to the name given in the text file.

Set objShell = CreateObject("WScript.Shell")

DO objShell.Run" Robocopy " strSource strDestination strOptions strLog
LOOP, Keep doing this for each entry in the provided text file.

My biggest issue is that I don't know how to get the script to open the text file, read a line and do something with it then go to the next line.  I also need it to pass the logfile name based on the entry in the text file.  

Thanks for your help!

Avatar of lpbenergy
lpbenergy
Flag of Afghanistan image

ASKER

Oops, left out some information...so just for clarity.

strSource = \\ServerA\Path\"Folder 1"
strDestination = \\ServerB\Path\"Folder 1"
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Actually yes, they do need to execute in parallel.  Normally I would agree that this would not be a good idea.  In my case I have found that is is necessary and actually does not significantly impact performance.
If you really want to start multiple robocopy you have to change line 11 to
objShell.Run "start /min Robocopy "& strSource & " " & strDestination & " " & strOptions & " /log:" & strLog
Thanks for your help.  Here is the final script.  Works like a champ.


Option Explicit
Dim objShell, objFSO
Dim strOptions, strLog, strSource, strDestination, strFolder
Dim txtFile

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set txtFile = objFSO.OpenTextFile("Robocopy_File.txt", 1)

do until txtFile.AtEndOfStream
  strFolder      = txtFile.ReadLine
  strSource      = "\\Server1\Share1" & "\" & strFolder
  strDestination = "\\Server2\Share2" & "\" & strFolder
  strOptions       = " /XF *.tif /S /maxage:14 /R:5 /w:2 /NFL /NDL /TEE "
  strLog         = strFolder & ".log"
objShell.Run "Robocopy "& strSource & " " & strDestination & " " & strOptions & " /log:" & strLog
loop
txtFile.Close