Skip to content

Instantly share code, notes, and snippets.

@theagreeablecow
Created June 6, 2012 11:31
Show Gist options
  • Save theagreeablecow/2881377 to your computer and use it in GitHub Desktop.
Save theagreeablecow/2881377 to your computer and use it in GitHub Desktop.
Multiple Robocopy Streams
Option Explicit
On Error Resume Next
Dim Source1, Source2, Source3, Destination1, Destination2, Destination3, BatchFile1, BatchFile2, BatchFile3
'******************************************
'Root Source folders to parse
Source1 = "\\server1\c$\folder1"
Source2 = "\\server1\share1"
Source3 = "\\server1\share2"
'Root Destination folders
Destination1 = "\\server2\c$\folder1"
Destination2 = "\\server2\share1"
Destination3 = "\\server2\share2"
'Batch file names
BatchFile1 = "Sync_Folder1.bat"
BatchFile2 = "Sync_Share1.bat"
BatchFile3 = "Sync_Share2.bat"
'******************************************
'1. Create the Batch files
CreateScript Source1,Destination1,BatchFile1
CreateScript Source2,Destination2,BatchFile2
CreateScript Source3,Destination3,BatchFile3
function CreateScript (Source,Destination,BatchFile)
Dim objFSO, txtOutput, objRootFolder, colFolders, objFolder
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set txtOutput = objFSO.CreateTextFile(BatchFile)
Set objRootFolder = objFSO.GetFolder(Source)
Set colFolders = objRootFolder.SubFolders
'Write robocopy cmd string for each subfolder
For Each objFolder in colFolders
txtOutput.Write "start robocopy *.* " & Source & "\" & objFolder.Name & " " & Destination & "\" & objFolder.Name & " /w:1 /r:1 /MIR" & vbCrLf
Next
'Close objects
txtOutput.Close
Set objFSO = Nothing
Set objRootFolder = Nothing
Set colFolders = Nothing
end function
'2. Optionaly run the batch files
Dim Shell
set shell=createobject("wscript.shell")
'shell.run BatchFile1
'wscript.sleep 50000
'shell.run BatchFile2
'wscript.sleep 50000
'shell.run BatchFile3
set shell=nothing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment