Dir FilesNumber()

  • Thread starter Thread starter ALESSANDRO Baraldi
  • Start date Start date
A

ALESSANDRO Baraldi

Hi all.

How to get the Number Of Files in a Folder in the wastest way
as possible...!

Now i'm using the API below on a Do..Loop cicle and each
one i add Counter=Counter+1
"FindFirstFile"
"FindNextFile"

Have i a faster method..?
Thanks.
 
That's how Windows does it: that's why it takes it so long sometimes when
you're looking at a large folder.

You could try using FileSystemObject, but everything I've read indicates
it's not going to be faster. Something like the following untested air code:

Function FilesInFolder(folderspec) As Long
Dim objFSO As Object
Dim objFolder As Object

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(folderspec)
FilesInFolder = objFolder.Count
Set objFolder = Nothing
Set objFSO = Nothing
End Function
 
Douglas J. Steele said:
That's how Windows does it: that's why it takes it so long sometimes when
you're looking at a large folder.

You could try using FileSystemObject, but everything I've read indicates
it's not going to be faster. Something like the following untested air code:

Function FilesInFolder(folderspec) As Long
Dim objFSO As Object
Dim objFolder As Object

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(folderspec)
FilesInFolder = objFolder.Count
Set objFolder = Nothing
Set objFSO = Nothing
End Function

It' perfect, now i test the time to performace...!

Thanks
 
Just for test i need to insert the right reference to Files object

objFolder.files.Count

Bye.
 
Back
Top