SCRIPT: Exclude files and directories read from a single file using Robocopy

Use this script and 2 textfiles which can be used to exclude files and folders.

robocopy.vbs
EXCLUDEDIRS = "C:\robocopy\excludedirs.txt"
EXCLUDEFILES = "C:\robocopy\excludefiles.txt"
ROBOCOPYLOCATION = "C:\robocopy\robocopy.exe"
SOURCELOCATION = "Y:\"
TARGETLOCATION = "D:\"
Const FOR_READING = 1
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(EXCLUDEDIRS, FOR_READING)
strDirExclude = objFile.ReadAll
objFile.Close
Set objFile = objFSO.OpenTextFile(EXCLUDEFILES, FOR_READING)
strFileExclude = objFile.ReadAll
objFile.Close
arrDirExclude = Split(strDirExclude, vbCrLf)
arrFileExclude = Split(strFileExclude, vbCrLf)
For Each dir In arrDirExclude
dirs = dirs + " /xd " + chr(34) + dir + chr(34)
Next
For Each bestand In arrFileExclude
bestanden = bestanden + " /xf " + chr(34) + bestand + chr(34)
Next
mycommand = ROBOCOPYLOCATION & chr(32) & SOURCELOCATION & chr(32) & TARGETLOCATION & " /COPYALL /S /mir /R:5 /W:10 /IPG:10 /TBD /ETA /LOG+:C:\ictivity\robo.log /TEE " & dirs & bestanden
WshShell.Run(mycommand)

Excludedirs.txt
y:\Program Files
y:\Profiles
y:\TSprofiles

Excludefiles.txt
y:\Application Partitions.vsd
y:\Domains.vsd
y:\Groups.csv
y:\AD\TEST\pagefile.sys

Advertisements

Posted on 07/10/2009, in Scripting. Bookmark the permalink. Leave a comment.

Comments are closed.

%d bloggers like this: