RayT
asked on
Running RoboCopy from Visual Basic Application
The following visual basic code fails to run.
Dim srce As String = "C:\Users\ZZZ\Documents\My Great Data\Audio"
Dim dest As String = "T:\My Great Data\Audio"
Dim MyProcess As Process
MyProcess = New Process
With MyProcess.StartInfo
.FileName = "C:\Windows\SysWOW64\roboc opy.exe"
.Arguments = srce & " " & dest & " /S /E /M"
.UseShellExecute = False
.CreateNoWindow = True
.RedirectStandardInput = False
.RedirectStandardOutput = True
.RedirectStandardError = True
End With
MyProcess.Start()
However running the following PowerShell script works fine
robocopy "C:\Users\ZZZ\Documents\My Great Data\Audio" "t:\My Great Data\Audio" /S /E /M
Why???
I think the problem is the fact that the srce & dest contains spaces.
How can I make this work?
Dim srce As String = "C:\Users\ZZZ\Documents\My
Dim dest As String = "T:\My Great Data\Audio"
Dim MyProcess As Process
MyProcess = New Process
With MyProcess.StartInfo
.FileName = "C:\Windows\SysWOW64\roboc
.Arguments = srce & " " & dest & " /S /E /M"
.UseShellExecute = False
.CreateNoWindow = True
.RedirectStandardInput = False
.RedirectStandardOutput = True
.RedirectStandardError = True
End With
MyProcess.Start()
However running the following PowerShell script works fine
robocopy "C:\Users\ZZZ\Documents\My
Why???
I think the problem is the fact that the srce & dest contains spaces.
How can I make this work?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks! I changed the line to
.Arguments = """" & srce & """" & " " & """" & dest & """" & " /S /E /J"
Everything works great!
.Arguments = """" & srce & """" & " " & """" & dest & """" & " /S /E /J"
Everything works great!
Completely subjective, but you can also use Chr(34), instead of double quoting the double quotes:
.Arguments = Chr(34) & srce & Chr(34) & " " & Chr(34) & dest & Chr(34) & " /S /E /M"
ASKER
Thanks. That makes it more readable.
.UseShellExecute = True
?