If interested this method uses a recursive algorithm to list all the folders, sub folders and the files of any directory passed to it. For this sample I have the start path hard coded in the Buttons onClick event but you could set it up to get the start path from a TextBox or what ever your preference.
cut and paste the code below into an new html page to test
NOTE: you may want to format the printout to make it look nicer.
<SCRIPT language = "VBScript">
Dim FSO
function TraverseTree(fldr)
Dim fc
Dim fo
Dim fls
Dim F_item
Set FSO = createobject("scripting.filesystemobject"
Set fo = FSO.GetFolder(fldr)
Set fc = fo.SubFolders
Set fls = fo.Files
For Each F_item In fls
document.write F_item
document.write "<p>"
Next
For Each F_item In fc
TraverseTree(fldr + "\" + F_item.Name)
Next
end function
</SCRIPT>
if i had a parent folder with 20 subfolder and each subfolder had 20 other sub folders and eac sub-sub-folder had another 20 folders, is it possible to loop through all those hundreds of folders and return the files for all as a whole?
I am not quite sure what you mean by returning the files as a "whole" but the algorithm would continue to loop (including writing the contents out to file or screen - which ever method you implement) until it either reaches the last level or runs out of stack space / memory.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.