2012-07-06 111 views
0

我遇到了一个问题,我觉得VBscript中有关运行robocopy的语法错误。VBscript Robocopy语法

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

Dim Command2 

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


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

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

我也有它回应命令和命令完全匹配我放在命令行中。

谢谢你,如果你需要任何解释,请让我知道。

+0

尝试此链接http://ss64.com/nt/robocopy.html – Amol 2012-07-06 14:20:52

+0

这是了解所有不同的命令是有用的,但是当我在命令行直接使用我的命令已经运行。所以我知道它的工作原理。我只是不知道为什么它不从vbs – parchambeau 2012-07-06 14:43:23

回答

1

你不说你如何试图'跑'Robocopy,但我想它是通过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 
+0

打电话时感谢您的帮助。我设法弄清楚了我的问题,它非常简单。我告诉我的Run运行command1而不是命令2 ....这就是我刚才复制和粘贴的部分代码,我已经写过,但没有经过它。因为我知道我的语法正确,所以在这个问题上花了几个小时试图找出答案。 – parchambeau 2012-07-07 04:07:51