0

我对我认为 VBscript 中关于运行 robocopy 的语法错误有疑问。

以下是我现在用来尝试运行 robocopy 的代码片段:

Dim Command2

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


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

问题是该命令不会产生任何错误,但它也不会将任何文件从本地路径复制到最终路径。从命令行执行时,它运行得非常好。任何帮助将不胜感激,因为这个简单的命令使我无法完成此脚本的其余部分。

我也让它回显命令,并且命令与我在命令行中输入的完全匹配。

谢谢,如果您需要更多解释,请告诉我。

4

1 回答 1

1

您没有说您是如何尝试“运行”的Robocopy,但我认为它是 via WScript.Shell.Run()

我碰巧没有Robocopy方便,但我确实使用 Windows 编写了一个示例XCopy。也许您可以调整我的简单XCopy示例,以更深入地了解您的问题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
于 2012-07-06T17:50:34.797 回答