-1

The script below works fine. It searches a specified location for .exe files and outputs a file which contains the location of the files.

All of that works great. Except I'd like the output file lines to all be enclosed in " ", how to do this?

Option Explicit 'force all variables to be declared

On Error Resume Next
Const ForWriting = 2
Dim objFSO
Set objFSO = CreateObject(Scripting.FileSystemObject)

Dim objTS 'Text Stream Object
Set objTS = objFSO.OpenTextFile("output_path", ForWriting, True)

Recurse objFSO.GetFolder("location_of_files")
objTS.Close()

Sub Recurse(objFolder)
    Dim objFile, objSubFolder

    For Each objFile In objFolder.Files
        If LCase(objFSO.GetExtensionName(objFile.Name)) = "exe" Then
            objTS.WriteLine(objfile.Path)
        End If
    Next

    For Each objSubFolder In objFolder.SubFolders
        Recurse objSubFolder
    Next
End Sub
Dijkgraaf
  • 9,324
  • 15
  • 34
  • 48
andmcq
  • 1

1 Answers1

0

Change this line:

objTS.WriteLine(objfile.Path)

To this:

objTS.WriteLine("""" & objfile.Path & """")

It looks weird because you have to double the embedded quotation marks.

Or instead you can use chr(34), like this:

objTS.WriteLine(chr(34) & objfile.Path & chr(34))

The chr() function converts the specified character code to a character.

Kevin Collins
  • 1,376
  • 1
  • 9
  • 13
  • This exact answer has been given [countless times before](https://www.google.com/search?safe=off&ei=5msRWZ_kNKeZgAaJlqyoCA&q=site%3Astackoverflow.com+vbscript+double+quotes&oq=site%3Astackoverflow.com+vbscript+double+quotes), it's not like escaping quotes in strings is a new thing. Flag and move on. – user692942 May 09 '17 at 07:16