Aug 9, 2002 #1 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
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
Aug 10, 2002 #2 Steve101 Programmer Mar 29, 2002 1,473 AU 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 Upvote 0 Downvote
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