Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WshShell.Run - Quotes and more quotes..help!?

Status
Not open for further replies.

brent01

Technical User
Jul 11, 2001
32
GB
I am writing a very basic VBscript.

It simply asks for input of a date, sets a variable to the date entered (variable name is 'Date') and then runs Xcopy to copy any files changed on or after the date entered. I have managed to set the variable using an InputBox (big deal, I hear everyone shout!) and that works fine.

The problem I am having is with the actual execution of Xcopy. I understand how to use Xcopy in cmd.exe but trying to get my script to run the command does not work.

I think it's something to do with file names / folder names e.g. "Documents and Settings" I know I need to use double quotes etc. when executing this command using WshShell.Run, but I can't seem to get it right. Any ideas please?

Here's the command -

WshShell.Run "Xcopy C:\Documents and Settings\User1\bex*.txt C:\Documents and Settings\User1\backups /D: "&Date


 
Hello brent01,

Put the whole path within chr(34) which is the quotes in unescaped form. In a sense, it is less confusing.
[tt]
WshShell.Run "Xcopy " & chr(34) & "C:\Documents and Settings\User1\bex*.txt" & chr(34) & " " & chr(34) & "C:\Documents and Settings\User1\backups /D: " & Date & chr(34)
[/tt]
regards - tsuji
 
You may try this:
WshShell.Run "Xcopy ""C:\Documents and Settings\User1\bex*.txt"" ""C:\Documents and Settings\User1\backups"" /D:" & Date
Note: I suggest not using a variable named Date, as Date() is a function.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Further note:

Upon re-reading this thread, I think PHV's advice is the correct one, placing the quotes at the right places. Mine above was wrong.

The equivalent version using chr(34) just for brent01's sake is this.
[tt]
WshShell.Run "Xcopy " & chr(34) & "C:\Documents and Settings\User1\bex*.txt" & chr(34) & " " & chr(34) & "C:\Documents and Settings\User1\backups" & chr(34) & " /D:" & Date
[/tt]
- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top