lpbenergy
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.Shel l")
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!
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.Shel
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!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
objShell.Run "start /min Robocopy "& strSource & " " & strDestination & " " & strOptions & " /log:" & strLog
ASKER
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.Shel l")
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
Set txtFile = objFSO.OpenTextFile("Roboc opy_File.t xt", 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
Option Explicit
Dim objShell, objFSO
Dim strOptions, strLog, strSource, strDestination, strFolder
Dim txtFile
Set objShell = CreateObject("WScript.Shel
Set objFSO = CreateObject("Scripting.Fi
Set txtFile = objFSO.OpenTextFile("Roboc
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
ASKER
strSource = \\ServerA\Path\"Folder 1"
strDestination = \\ServerB\Path\"Folder 1"