I need to get a count of the number of files in a directory. I could get the names of all the files in the directory using System.IO.Directory.GetFiles()
and t
So far, in most languages I came across, you get this information only by walking the folder and counting the files. I doubt there is a Windows API call to get only the count (but I can be surprised!).
Advantage of the method: flexibility - you can filter out some file types, walk down recursively or ignore folders, etc.
If the method is slow for you, maybe you should get a better method, like not creating an array filled with directory info (takes time to fill it! not to mention memory cost and garbage collection time) but using an iterator: a bit more work (but once you get the function, it is always there) but much more efficient.