#include#include int main() { CFileFind finder; BOOL bIsFound = finder.FindFile(L"C:\\Users\\john\\Desktop\\*.*"); while (bIsFound) { bIsFound = finder.FindNextFile(); CString filename = finder.GetFileName(); std::wcout << filename << std::endl; } return 0; }
#includeIn this example, we use the IsDirectory method to check if the current file found by the FindNextFile method is a directory. If it is a directory, we print out its name using the GetFileName method. We also skip the "." and ".." directories using the IsDots method. The CFileFind class and its methods are part of the MFC library in C++.#include int main() { CFileFind finder; BOOL bIsFound = finder.FindFile(L"C:\\Users\\john\\Desktop\\*.*"); while (bIsFound) { bIsFound = finder.FindNextFile(); if (finder.IsDots() || !finder.IsDirectory()) continue; CString dirname = finder.GetFileName(); std::wcout << dirname << std::endl; } return 0; }