Is there any function to count the number of files in a folder except the findfirst, findnext api´s?
Printable View
Is there any function to count the number of files in a folder except the findfirst, findnext api´s?
Use Dir
Code:a = Dir(path)
Do While Len(a)
FileNo = FileNo + 1
a=Dir
Loop
that bit of code will include other folders as files, so you will get a aflse result in some cases.
Use the FSO to get more reliable results.
[code]
'count files in a directory using FileSystemObject
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
Set FSO = FSO.GetFolder("C:\my documents")
MsgBox FSO.Files.Count
'
'<<<<<<<<<<<<<<<<<<<?>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'count files in a directory using dir
Dim iFiles As Integer
Dim sDir As String
sDir = Dir("C:\My Documents\*.*", vbNormal + vbHidden + vbArchive + vbReadOnly + vbSystem)
While sDir <> ""
iFiles = iFiles + 1
sDir = Dir
Wend
MsgBox iFiles
[code]
The function i described does not include Directories.
It returns the number of files.
Check it out for yourself.
I´m going to create a component that optimizes the upload of files to a database (file stored in filesystem, path saved in db). It´s says that in order to speed things up you should store 500 files at the most in the same folder. So I don´t have to count all the files in subfolders.