1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Rep Power

    How to pass a VBScript variable to command prompt

    Just have look at below code:

    Dim oFSO,FolderName,Path
    Set oFSO = CreateObject("Scripting.FileSystemObject")

    FolderName=InputBox("Enter Folder Name")


    oFSO.CreateFolder FolderPath

    Dim oShell
    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.
  2. #2
  3. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Rep Power
    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.
    Doug G
    I've never been able to appreciate the sublime arrogance of folks who feel they were put on earth just to save other folks from themselves .." - Donald Hamilton

IMN logo majestic logo threadwatch logo seochat tools logo