Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

filesystemobject - subfolders

Status
Not open for further replies.

gooseriver

IS-IT--Management
Aug 4, 2006
93
CA
Using FileSystemObject how can I display the names of the files in the subfolders within that folder and include the subfolder in which the file is located. IE:


Folder structure:

Parent Folder("c:\temp")
Subfolder1 Subfolder2
test.doc code.doc
test1.doc code1.doc
test2.doc code2.doc

output:
subfolder1\test.doc
subfolder1\test1.doc
subfolder1\test2.doc

subfolder2\code.doc
subfolder2\code2.doc
subfolder2\code3.doc


-
 
or do little while ;-)

I've just always wanted to say that. I know, I'm dumb

[sub]____________ signature below ______________
You are a amateur developer until you realize all your code sucks.
Jeff Atwood[/sub]
 
Do you have any sample code... I am able to list al the files in a parent folder but not the content in the subfolders within that folder...
 
You have to write a recursive function for that.

More or less while running through your function call the same function when you hit a subfolder etc..

google recursive function FSO

This is probably as common as "How do I connect to a database?" as far as a google search

[sub]____________ signature below ______________
You are a amateur developer until you realize all your code sucks.
Jeff Atwood[/sub]
 
Have you considered simply enabling "directory browsing" on the web server?
 
Hi Chris,

This only shows the files in the parent folder not the subfolders includ4ed..
 
Yeah but read through the code...

At the bottom of the first grey code box you can set it gets a subfolders collection object into a variable and then in the second grey code box it has a loop where it flips through the collection with a For Each loop... now in this particular example it just does a Response.Write of a fixed string "Edited listing" but there is no reason why you couldn't modify the code to print the folder name instead.
 
In my lopp I have For Each cntFile in testFolder1.fiesl.. Can I add testFolder2.files to this loop, if yes how?

Set filesys = Server.CreateObject("Scripting.filesystemObject")
Set testFolder1 = filesys.Getfolder(Folder1)
Set testFolder2 = filesys.Getfolder(Folder2)

'Loop through the files collection
Dim cntFile, filecount
filecount = 0
For Each cntFile in testFolder1.files
if lcase(right(cntFile.Name, 4)) = ".xls" then
filecount = filecount + 1
fileName = fileName & cntFile.name
fileName = fileName & ";"
end if
Next


Set testFolder1 = Nothing
Set cntFile = Nothing
Set filesys = Nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top