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

    Join Date
    Feb 2014
    Posts
    1
    Rep Power
    0

    How to pass a VBScript variable to command prompt


    Hi,
    Just have look at below code:

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

    FolderName=InputBox("Enter Folder Name")

    FolderPath="C:\"+FolderName

    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
    Posts
    14,428
    Rep Power
    4539
    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
    ======
    The man who doesn't read good books has no advantage over the man who can't read them.
    --Mark Twain

IMN logo majestic logo threadwatch logo seochat tools logo