Is it possible to use Windows API function FindFirstFile
to search for multiple file types, e.g *.txt
and *.doc
at the same time?
I tried to separate patterns with '\0'
but it does not work - it searches only the first pattern (I guess, that's because it thinks that '\0'
is the end of string).
Of course, I can call FindFirstFile
with *.*
pattern and then check my patterns or call it for every pattern, but I don't like this idea - I will use it only if there no other solutions.
This is not supported. Run it twice with different wildcards. Or use *.*
and filter the result. This is definitely the better choice, wildcards are ambiguous anyway due to support for legacy MS-DOS 8.3 filenames. A wildcard like *.doc will find both .doc and .docx files for example. A filename like longfilename.docx
also creates an entry named LONGFI~1.DOC
The MSDN docs mention nothing about FindFirstFile
allowing multiple search patterns, hence it doesn't exist.
In this case your best bet is to scan using an open selection (like C:\\some directory\*
or *
) and then filter based on WIN32_FIND_DATA
's cFileName
member, using strrchr
(or the appropriate Unicode variant) to find the extension. It should run pretty fast for the small set of characters that make up a file extension.
If you know the that all the extensions are say 3 characters, you should be able to mask it off as *.???
to speed things up.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With