Dir FilesNumber()

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.
 
D

Douglas J. Steele

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
 
A

ALESSANDRO Baraldi

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
 
A

ALESSANDRO Baraldi

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

objFolder.files.Count

Bye.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top