我正在尝试使用VBS和robocopy将共享镜像到本地计算机。该脚本有效,但共享中的文件夹在路径中有空格,我无法使用带空格的路径。
InputFile = "\\baardrob\Software application\Scripts\Input\computers.Txt"
Const OverWriteFiles = True
Set oShell = WScript.CreateObject("WSCript.shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(InputFile)
Set myLog = objFSO.OpenTextFile("\\baardrob\Software application\Scripts\Input\failed.txt", 2)
Do Until objFile.AtEndOfStream
strComputer = objFile.ReadLine
On Error Resume Next
oShell.run "robocopy "\\baardrob\software application" c:\temps /mir"
If Err Then myLog.WriteLine strComputer
On Error Goto 0
Loop
myLog.Close
MsgBox "Done"
编辑: Ekkehard.Horner解决方案有效,但我有另一个问题。 c:\ temps只是试图让它发挥作用,它实际上应该是写“\”& strComputer“\ c $”,但这不起作用。
我已经尝试过了:
InputFile = "\\baardrob\Software application\Scripts\Input\computers.Txt"
Const OverWriteFiles = True
Set oShell = WScript.CreateObject("WSCript.shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(InputFile)
Set myLog = objFSO.OpenTextFile("\\baardrob\Software application\Scripts\Input\failed.txt", 2)
Do Until objFile.AtEndOfStream
strComputer = objFile.ReadLine
On Error Resume Next
oShell.run "robocopy ""\\baardrob\Software application"" ""\\"" & strComputer & ""\c$"" /mir"
If Err Then myLog.WriteLine strComputer
On Error Goto 0
Loop
myLog.Close
MsgBox "Done"
答案 0 :(得分:1)
您
"robocopy "\\baardrob\software application" c:\temps /mir"
无效VBScript:
>> s = "robocopy "\\baardrob\software application" c:\temps /mir"
>>
Error Number: 1002
Error Description: Syntax error
通过使用“”(参见here)转义'内部'引号来修复它们:
>> s = "robocopy ""\\baardrob\software application"" c:\temps /mir"
>> WScript.Echo s
>>
robocopy "\\baardrob\software application" c:\temps /mir
更新wrt以增加问题:
>> strComputer = "pipapo"
>> s = "robocopy ""\\baardrob\Software application"" ""\\"" & strComputer & ""\c$"" /mir"
>> WScript.Echo s
>>
robocopy "\\baardrob\Software application" "\\" & strComputer & "\c$" /mir
>> s = "robocopy ""\\baardrob\Software application"" ""\\" & strComputer & "\c$"" /mir"
>> WScript.Echo s
>>
robocopy "\\baardrob\Software application" "\\pipapo\c$" /mir