0

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.

parchambeau
  • 1,141
  • 9
  • 34
  • 56
  • Try this Link http://ss64.com/nt/robocopy.html – Amol Chavan Jul 06 '12 at 14:20
  • That was useful to know about all the different commands, but my command already runs when I use it directly in the command line. So I know that it works. I just do not know why it doesn't when called from vbs – parchambeau Jul 06 '12 at 14:43

1 Answers1

0

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
Community
  • 1
  • 1
DavidRR
  • 18,291
  • 25
  • 109
  • 191
  • Thank you for your help. I managed to figure out my problem, it was so ridiculously simple. I was telling my Run to run command1 instead of command 2....thats what I get for just copy and pasting parts of code that I already have written without going over it. Was going at that problem for hours trying to figure it out because I knew I had the syntax right. – parchambeau Jul 07 '12 at 04:07