Help with spaces in a script

Posted on 2012-03-16
Last Modified: 2012-04-13
The following code works fine, unless FSOURCE and FDESTINATION have spaces in them. Please can somebody advise how I can handle spaces with it?

Set WshShell = WScript.CreateObject("WScript.Shell")
Return = WshShell.Run("%comspec% /C \\srhtimtss\SLogic\Files\Backup\robocopy /E /MIR /R:1 /W:1 /V /TEE /log:\\Srhtimtss\installlogs\VI_Logs\"&MyNumber&".txt "&FSOURCE&" "&FDESTINATION&"", 0, true)

Open in new window

Thank you.
Question by:IM&T SRFT
LVL 46

Expert Comment

by:Martin Liss
ID: 37729322

or it could be


Author Comment

ID: 37729352
Unfortunately neither of those worked.

Author Comment

ID: 37729373
I've just worked it out.

If anybody would like to see this in future, here's the solution:

Set WshShell = WScript.CreateObject("WScript.Shell")
Return = WshShell.Run("%comspec% /C \\srhtimtss\SLogic\Files\Backup\robocopy /E /MIR /R:1 /W:1 /V /TEE /log:\\Srhtimtss\installlogs\VI_Logs\"&MyNumber&".txt """&FSOURCE&""" """&FDESTINATION&"""", 0, true)

Open in new window

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.


Expert Comment

ID: 37729377
You can also try:

"& "'" &  [FSOURCE] & "'" & " " & "'" & [FDESTINATION] &"'" &"

That is a ' surrounded by quotes.
So that it is interpreted as
LVL 53

Accepted Solution

Bill Prew earned 500 total points
ID: 37750649
For what it's worth, here's I approach these, using a small function that saves typing and for improves readability.
Set WshShell = WScript.CreateObject("WScript.Shell")

Return = WshShell.Run("%COMSPEC% /C \\srhtimtss\SLogic\Files\Backup\robocopy /E /MIR /R:1 /W:1 /V /TEE /log:\\Srhtimtss\installlogs\VI_Logs\" & MyNumber & ".txt " & Quote(FSOURCE) & " " & Quote(FDESTINATION), 0, true)

Function Quote(s)
   Quote = Chr(34) & s & Chr(34)
End Function

Open in new window

LVL 53

Expert Comment

by:Bill Prew
ID: 37841882


Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now