parchambeau
parchambeau

Reputation: 1141

VBscript Robocopy Syntax

I am having a problem with what I think is a syntax error in VBscript regarding running robocopy.

The following is a code snippet of what I now using to try to run robocopy:

Dim Command2

sLocalDestinationPath = "C:\Script\files\outzips\"
sFinalDestinationPath = "C:\CopyTestFolder\"


Command2 = "Robocopy.exe " & sLocalDestinationPath & " " & sFinalDestinationPath 

The thing is that the command does not produce any errors, but it also does not copy any files from the local path to the final path. It runs perfectly fine when executed from the command line. Any help would be greatly appreciated because this simple command is keeping me from finishing the rest of this script.

I also have it echoing out the command and the command matches exactly what I put in the command line.

Thank you, if you need anymore explanation just let me know.

Upvotes: 0

Views: 9033

Answers (1)

DavidRR
DavidRR

Reputation: 19397

You don't say how you are trying to 'run' Robocopy, but I presume it is via WScript.Shell.Run().

I don't happen to have Robocopy handy, but I did work up an example using Windows XCopy. Perhaps you can adapt my simple XCopy example to gain more insight into your problem with Robocopy.

Option Explicit

' XCOPY doesn't Like trailing slashes in folder names
Const sLocalDestinationPath = "C:\Script\files\outzips"
Const sFinalDestinationPath = "C:\CopyTestFolder"

Dim Command2 : Command2 = _
    "XCOPY" _
    & " " & sLocalDestinationPath _
    & " " & sFinalDestinationPath _
    & " /E /I /Y" _
    & ""

Dim oSh : Set oSh = CreateObject("WScript.Shell")

WScript.Echo "Cmd: [" & Command2 & "]"

On Error Resume Next
Dim nRetVal : nRetval = oSh.Run(Command2, 0, True)

If Err Then
    WScript.Echo "An exception occurred:" _
           & vbNewLine & "Number: [" & Hex(Err.Number) & "]" _
           & vbNewLine & "Description: [" & Err.Description & "]" _
           & ""
Else
    If nRetVal Then
         WScript.Echo "Copy error: [" & nRetVal & "]"
    Else
         WScript.Echo "Copy succeeded."
    End If
End If

Set oSh = Nothing

' XCOPY options:
'
' /E    Copies directories and subdirectories, including empty ones.
'       Same as /S /E. May be used to modify /T.
'
' /I    If destination does not exist and copying more than one file,
'       assumes that destination must be a directory.
'
' /Y    Suppresses prompting to confirm you want to overwrite an
'       existing destination file.

' End

Upvotes: 0

Related Questions