February 18th, 2014, 07:52 AM
How to pass a VBScript variable to command prompt
Just have look at below code:
Set oFSO = CreateObject("Scripting.FileSystemObject")
FolderName=InputBox("Enter Folder Name")
set oShell = CreateObject("WScript.Shell")
oShell.Run ("cmd /c %comspec% /c echo robocopy X: &FolderPath /MAXAGE:3 > D:\test.bat")
I am trying to copy some files from one location to another using ROBOCOPY onto my PC. X: is the mapped drive which i already have and i am using "&FolderPath" to get the exact path (like C:\<FolderName>) to be written in test.bat. But when the batch file gets created it does not have any content. I think i am making a mistake while passing the folder location as &FolderPath. Can anyone tell me how we can pass the VBScript variable to command prompt so that i will get the exact location (like C:\<FolderName> written in my batch file.
February 18th, 2014, 03:30 PM
You should use & not + to concatenate strings in VB.
To help isolate the problem, you could messagebox the FolderPath variable just before you send it to the run method to verify it has the content you expect.
Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.