title: Creating a VBS file with the ability to write out to a text file
body: <p>I have a VBS file that I am trying to use to determine what folders and files are in a certain directory. I believe I have the code written correctly, but whenever I try to write out the file or current directory I get a blank text document with nothing but the root directory written out. Any advice would be greatly appreciated.</p>
  
  <pre><code>Dim NewFile
  
  Function GetFolders (strFolderPath)
  Dim objCurrentFolder, colSubfolders, objFolder, files
  
  Set objCurrentFolder = objFSO.GetFolder(strFolderPath)
  Set colSubfolders = objCurrentFolder.SubFolders
  
  For Each objFolder In colSubfolders
  
  NewFile.WriteLine("    - " &amp; objFolder.Path)
  
  Set files = folder.Files
  For each folderIdx In files
      NewFile.WriteLine("        - "&amp; folderIdx.Name)
  Next
  
  Call GetFolders (objFolder.Path)
  
  Next
  
  End Function
  
  Dim fso, sFolder
  
  Set fso = CreateObject("Scripting.FileSystemObject")
  sFolder = Wscript.Arguments.Item(0)
  If sFolder = "" Then
    Wscript.Echo "No Folder parameter was passed"
    Wscript.Quit
  End If
  Set NewFile = fso.CreateTextFile(sFolder&amp;"\FileList.txt", True)
  
  NewFile.WriteLine(sFolder)
  
  Call GetFolders(sFolder)
  
  NewFile.Close
  </code></pre>