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.
- http://saltwetbytes.wordpress.com/2010/05/04/vbscript-grabbing-subfolders-recursively/
http://technet.microsoft.com/en-us/library/ee198872.aspx
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 & "|" & Subfolder.Path End If GetAllSubFolders Subfolder, pSubFoldersList Next GetAllSubFolders = pSubFoldersList End Function
My question is: Is this a good aproach when it comes to creating a recursive function (using a parameter for storing previous results)?
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)
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?)