c++regexfile-find

Find files with certain file extensions c++


I can find .jpg files But how can I find .jpg, .bmp, .png .... files?

Mask

LPWSTR mask = stoL(path + "*.(jpg)");

Handler initialization

HANDLE hf = FindFirstFile(mask, &FindFileData);

String to LPWSTR

LPWSTR stoL(string s) {
    return CA2T(s.c_str());
}

Solution

  • If you want to find multiple extensions, you have two choices: you can either search separately for each extension you care about, or you can do one search for all files, then see if each file fits one of the extensions you care about.

    Something like *.(jpg|png|bmp) just isn't going to work--FindFirstFile and FindNextFile don't recognize (, | or ), so given this pattern, it'll be searching for a single extension--i.e., all files that literally have the characters (jpg|png|bmp) as their extension (which will normally fail, of course).