-2

I want to create a vbscript that uses robocopy, which is fine, but I was hoping you can provide me the most elegant way to do this...

Copy all contents (Files and folders) of User Directory to this location EXCEPT copy AppData directory (Files and folders) to a different location AND copy Desktop directory to a different location

If FSO.folderExists(SOURCE & strAccount & "\AppData") Then
    oShell.Run "robocopy " & appDataSource & " " & appDatastrDestination & appDatastrSwitches
Else
    oShell.Run "robocopy " & strSource & " " & strDestination & strSwitches
End If
JNevill
  • 46,980
  • 4
  • 38
  • 63
Rico
  • 7
  • 7

1 Answers1

0

If you want to use all VBScript, you should be able to work with this. Edit - Added subs to reduce code.

On Error Resume Next

strSourceProfile = "C:\Users\NewUser"

strBaseFolder1 = "C:\Temp\"
strBaseFolder2 = "C:\Temp\Backup\"
strDestFolder1 = "C:\Temp\Backup\Profile\"
strDestFolder2 = "C:\Temp\Backup\Desk\"
strDestFolder3 = "C:\Temp\Backup\App\"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Const OverWriteFiles = True

' make sure target folders exist
ChkFolder strBaseFolder1
ChkFolder strBaseFolder2
ChkFolder strDestFolder1
ChkFolder strDestFolder2
ChkFolder strDestFolder3

For Each objFolder In objFSO.GetFolder(strSourceProfile).SubFolders
  If objFolder.Name <> "Desktop" And objFolder.Name <> "AppData" Then
    CopyToTarg objFolder.Path, strDestFolder1
  End If
Next
For Each objFolder In objFSO.GetFolder(strSourceProfile).SubFolders
  If objFolder.Name = "Desktop" Then
    CopyToTarg objFolder.Path, strDestFolder2
  End If
Next
For Each objFolder In objFSO.GetFolder(strSourceProfile).SubFolders
  If objFolder.Name = "AppData" Then
    CopyToTarg objFolder.Path, strDestFolder3
  End If
Next  

Sub ChkFolder(strFolder)
  If Not(objFSO.FolderExists(strFolder)) Then
    objFSO.CreateFolder(strFolder)
  End If
End Sub

Sub CopyToTarg(strSource , strTarget)
  objFSO.CopyFolder strSource , strTarget , OverWriteFiles
End Sub
Randy Schuman
  • 357
  • 1
  • 9