sjors86
sjors86

Reputation: 3

VBS: oShell.run and robocopy not working

I'm trying to mirror a share to a local computer using VBS and robocopy. The script works, but the folder from the share has spaces in the path and I can't get it to work with a path with spaces.

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"

EDIT: Ekkehard.Horner solution worked, I have another problem though. c:\temps was just a attempt to get it work, it should actually be writing to "\" & strComputer "\c$", but this doesn't work.

I allready tried:

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"

Upvotes: 0

Views: 858

Answers (1)

Ekkehard.Horner
Ekkehard.Horner

Reputation: 38745

Your

"robocopy "\\baardrob\software application" c:\temps /mir" 

is not valid VBScript:

>> s = "robocopy "\\baardrob\software application" c:\temps /mir"
>>
Error Number:       1002
Error Description:  Syntax error

Fix 'inner' quotes by escaping them using "" (cf. here):

>> s = "robocopy ""\\baardrob\software application"" c:\temps /mir"
>> WScript.Echo s
>>
robocopy "\\baardrob\software application" c:\temps /mir

Update wrt to augmented question:

>> 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

Upvotes: 1

Related Questions