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

How to read Number of Files?

Status
Not open for further replies.

Cap2010

Programmer
Mar 29, 2000
196
CA
HI,

Without any interface, want to read a folder
and to count number of files in a folder.
How do I count number of files in a folder?

Please help.

Cap

 
One way to do it is to use the Dir function. An example function is shown below:

Function CountFiles(Folder)
CountFiles = 0
FileName = Dir(Folder)
While Len(FileName) > 0
CountFiles = CountFiles + 1
FileName = Dir
Wend
End Function

To count the files in the root folder of the C drive, you would then use

NoOfFiles = CountFiles("C:\")

In a lower level folder an example might be:

NoOfFiles = CountFiles("C:\SomeFolder\")

Make sure you dont forget the last backslash.

If you want to count just the .doc file, you could use:

NoOfFiles = CountFiles("C:\SomeFolder\*.doc")

Hope this helps,

Cheers,

Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top