title: vbscript recursion programming-techniques
body: <p>I am looking for some expert insight concerning recursion within vbscript.
  From various examples found online I created the following code, which works by the way.</p>
  
  <ul>
  <li><a href="http://saltwetbytes.wordpress.com/2010/05/04/vbscript-grabbing-subfolders-recursively/" rel="nofollow">http://saltwetbytes.wordpress.com/2010/05/04/vbscript-grabbing-subfolders-recursively/</a></li>
  <li><p><a href="http://technet.microsoft.com/en-us/library/ee198872.aspx" rel="nofollow">http://technet.microsoft.com/en-us/library/ee198872.aspx</a></p>
  
  <pre><code>Function GetAllSubFolders(RootFolder, ByRef pSubfoldersList)
      Dim fso, SubFolder, root
      Set fso = CreateObject("scripting.filesystemobject")
      set root = fso.getfolder(RootFolder)
      For Each Subfolder in root.SubFolders
          If pSubFoldersList = "" Then
              pSubFoldersList = Subfolder.Path         
          Else
              pSubFoldersList = pSubFoldersList &amp; "|" &amp; Subfolder.Path
          End If
          GetAllSubFolders Subfolder, pSubFoldersList
      Next
      GetAllSubFolders = pSubFoldersList
  End Function
  </code></pre></li>
  </ul>
  
  <p>My question is: Is this a good aproach when it comes to creating a recursive function (using a parameter for storing previous results)?</p>
  
  <p>I prefer putting this in a (self-contained) "function", so the procedure returns the subsubfolders as the result. But most of the examples found use a "sub" I always get confused when it comes to "sub" vs "function" (I understand when you want a procedure that needs to return something you use a function, imho this seems to be the case in this example)
  But I could also use a "sub" and just simple reference the output parameter (ByRef pSubfoldersList) </p>
  
  <p>So what is the best practise or is it better to use a whole different approach all together?
  (the function is this examples is also very slow compared to [shell.exec "cmd /c dir RootFolder /s /b /a:d"], I guess this is a side effect from the recursion or maybe the FSO is just really slow?)</p>