CFileItemList fileList; // create an instance of the class CString pathName = "C:\\MyFolder\\"; WIN32_FIND_DATA findData; HANDLE hFind = FindFirstFile(pathName + "*.*", &findData); if (hFind != INVALID_HANDLE_VALUE) { do { if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { fileList.SetContent(pathName + findData.cFileName); } } while (FindNextFile(hFind, &findData)); FindClose(hFind); }
CFileItemList folderList; // create a separate instance for folders CString pathName = "C:\\MyFolder\\"; WIN32_FIND_DATA findData; HANDLE hFind = FindFirstFile(pathName + "*.*", &findData); if (hFind != INVALID_HANDLE_VALUE) { do { if ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && (lstrcmp(findData.cFileName, ".") != 0) && (lstrcmp(findData.cFileName, "..") != 0)) { folderList.SetContent(pathName + findData.cFileName); } } while (FindNextFile(hFind, &findData)); FindClose(hFind); }This example adds all the subfolders in the "C:\MyFolder" directory to a separate CFileItemList object. The two special directories "." and ".." are excluded from the list.