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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Count using FSO

Status
Not open for further replies.

Nickela

MIS
Oct 22, 2002
29
0
0
US
Does anyone know how to very quickly find out the number of files in a folder including the number of files in all of its subfolders? I have been using the folder.files.count method in the FSO, but this only gives me the number of files in the top folder, not its subfolders. I know that I can do a loop to scan through all of the subfolders as well, but this method wouldn't be suitable for the program I am designing. Any ideas?

Thanks for any help!
 
I gave-up on FSO as the mere mention of it triggered a scripting alert on Norton. Not sure if that applies to debug only.

I wrote a prog looking for duplicate filenames and in that I had to loop. and it dealt with subfolders as it found them rather than collecting all posible instances - but if all you want to do is count it should not be logistically that onerous. The dir command gave me one name per "dir" (after the intial one for a specific name like *.*) it was tedious only in visualising it but once sussed it was elegant enough.
 
You'll need to recursively walk through the directory tree, keeping a running total.

I posted some code do that, using FSO, in the following thread: thread705-594561

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Well if you do decide to loop thru here's a function that works for me.

Private Function GetFileCount(strFolder As String) As Long
On Error Resume Next
Dim fso As New FileSystemObject
Dim fldr As Scripting.Folder
GetFileCount = GetFileCount + fso.GetFolder(strFolder).Files.Count
For Each fldr In fso.GetFolder(strFolder).SubFolders
GetFileCount = GetFileCount + GetFileCount(fldr.Path)
Next
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top