It is well known that finding the maximum of a list, in general, requires all items to be checked. And I believe that the most efficient way to do that is to use FindFirstFile/FindNextFile
or related APIs. It's hard to imagine that there will be any real way to improve on the official system API for enumerating files.
That was certainly the opinion offered here: Is there a faster alternative to enumerating folders than FindFirstFile/FindNextFile with C++? Note that I am rejecting out of hand the option of parsing the file system by hand. I don't regard that as being very practical.
On the other hand, this answer offers hope that FindFirstFileEx
with FindExInfoBasic
and FIND_FIRST_EX_LARGE_FETCH
may lead to better performance than plain old FindFirstFile
.
You may need to look for an alternative solution to your problem, one that does not involve repeated enumerations of a directory full of files. Perhaps using a database so that you can take advantage of indexing. In fact, it is plausible that the built-in indexing service could be of use.