VBScript XCopy

B1izzard
B1izzard used Ask the Experts™
on
I am trying to execute a simple script to copy folders from one location to another using XCopy, and it works ok if I do not have spaces in the filepath.  The problem is when I do, it doesn't work.  Here is what I have so far.

Set oShell = CreateObject("WScript.Shell")
strCommand = oShell.Run("Xcopy D:\source\folders D:\destination\ /X /E", 0, True)

If I change it to
strCommand = oShell.Run("Xcopy D:\source\my folders D:\my destination\ /X /E", 0, True)
then it does not work.

I've tried double quotes chr34 and all that, but haven't nailed it yet.  What is the proper syntax to get this to work?  
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Try this.


Set oShell = CreateObject("WScript.Shell")
oShell.Run "Xcopy " & Chr(34) & "D:\source\folders" & Chr(34) & _
    " " & Chr(34) & "D:\my destination\" & Chr(34) & " /X /E", 0, True

Open in new window

Author

Commented:
It works.  Thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial