I'm developing a C++ console application that has to manage files on Windows OS. I need to obtain a 'list' of file names which have a specific extension. I've found a lot of solutions, the most suggested one is the following one:
HANDLE hFind;
WIN32_FIND_DATA data;
hFind = FindFirstFile("C:\\PWS\\*.sda", &data);
if (hFind != INVALID_HANDLE_VALUE) {
do {
cout << data.cFileName << endl;
} while (FindNextFile(hFind, &data));
FindClose(hFind);
}
Suppose I have these files inside the C:\\PWS folder:
- f001.sdac
- f002.sda
- f003.sdab
- f004.sda
The above code prints all of them, while I only need f002.sda and f004.sda.
Any hint?
NB: I don't want to use boost library.