Using variable (which includes spaces) in vbscript shell.run

ColDon

New member
Local time
1:02 PM
Messages
2
Unable to find anything specific for this other than spaces in actual file paths. I know I can deal with this by using the actual path and file name enclosed by 3 quotes (inverted commas) but this would have to be changed each time I ran the script. Because thay would be very tedious I need the path and file name to be in the 2 variables as they will be constantly changing

The path will be in var1 and the file name in var2 as follows:

Var1 = "C:\Specials\Blues And Twos\"
Var2 = "Luna Pic.jpg"

Here is the relevent part of my script.

Set shell = CreateObject("WScript.Shell")
shell.Run Var1 & Var2, 1, false

This is no problem running this if there are no spaces iin variables Var1 and Var2. Unfortunately there are in both so how can I get this to run. I know the answer lies in the placing of the quotes so I've tried various combinations but without success.

Any help would be gratefully received.
 

My Computer

Computer type
PC/Desktop
OS
Windows 7 Home Premium 64 bit
Welcome to the forurm it doesnt allow spaces but Itry to avoid spaces in names because of these kind of issues. One thing you can try, which is how you get around names with spaces in a vbscript is using triple quotes (""") to open and close your statement. Example: cscript.exe """%deployroot%\Applications\my appli with space\myScript.vbs"""
 

My Computer

Computer type
PC/Desktop
OS
win 8 32 bit
Thanks for your reply Samuria but as I said it will not accept the 3 quotes as it treats a variable as a file path+name hence the rejection under "cannot find file". It does not recognise that the variable contains that information.
 

My Computer

Computer type
PC/Desktop
OS
Windows 7 Home Premium 64 bit
Back
Top