putting quotes around a string in VB Script  -  Windows 7

morinia
morinia used Ask the Experts™
on
Experts,

I have a string that has the address of a directory.  I just built this string and now I want to see if it exists.  How do I add quotation marks around the directory?

Currently string  myDir has the value below in it.



myDir= \\Main\FolderA\FolderB\FolderC\FolderD

I need  "\\Main\FolderA\FolderB\FolderC\FolderD"  to test the presence of the folder
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2012

Commented:
Try

myDir= '"\\Main\FolderA\FolderB\FolderC\FolderD"' <--singles quotes on outside of string

myDir= ""\\Main\FolderA\FolderB\FolderC\FolderD"" <--2 double quotes on outside of string

myDir= """\\Main\FolderA\FolderB\FolderC\FolderD""" <--3 double quotes on outside of string
IT / Software Engineering Consultant
Top Expert 2016
Commented:
I use a small function for this, as shown below:

myDir = Quote("\\Main\FolderA\FolderB\FolderC\FolderD")

' Small routine to add double quotes around a string
Function Quote(strText)
   Quote = Chr(34) & strText & Chr(34)
End Function

Open in new window

~bp
You don't need quotation marks if myDir is a string variable, just pass myDir to your function that tests the path.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial