Solved

Help with spaces in a script

Posted on 2012-03-16
6
181 Views
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.
0
Comment
Question by:IM&T SRFT
6 Comments
 
LVL 46

Expert Comment

by:Martin Liss
ID: 37729322
"[&FSOURCE&]" "[&FDESTINATION&]"

or it could be

"&[FSOURCE]&" "&[FDESTINATION]&"
0
 

Author Comment

by:IM&T SRFT
ID: 37729352
Unfortunately neither of those worked.
0
 

Author Comment

by:IM&T SRFT
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

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 9

Expert Comment

by:macarrillo1
ID: 37729377
You can also try:

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

That is a ' surrounded by quotes.
So that it is interpreted as
' FSOURCE '
0
 
LVL 52

Accepted Solution

by:
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

~bp
0
 
LVL 52

Expert Comment

by:Bill Prew
ID: 37841882
Thanks.

~bp
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Unlike scripting languages such as C# where a semi-colon is used to indicate the end of a command, Microsoft's VBScript language relies on line breaks to determine when a command begins and ends. As you can imagine, this quickly results in messy cod…
This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

863 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

23 Experts available now in Live!

Get 1:1 Help Now