void RecurseAddDir(LPCTSTR path, CAtlList<CString>& paths) { CFileFind finder; BOOL bFound = finder.FindFile(PathUtils::CombinePaths(path, _T("*.*"))); while (bFound) { bFound = finder.FindNextFile(); if (!finder.IsDots() && finder.IsDirectory()) { CString folderPath = finder.GetFilePath(); paths.AddTail(folderPath); RecurseAddDir(folderPath, paths); } } }
void ParseDirs(CAtlList<CString>& paths) { POSITION pos = paths.GetHeadPosition(); while (pos) { POSITION prevPos = pos; CString fn = paths.GetNext(pos); // Try to follow link files that point to a directory if (IsLinkFile(fn)) { fn = ResolveLinkFile(fn); } if (IsDir(fn)) { CAtlList<CString> subDirs; RecurseAddDir(fn, subDirs); // Add the subdirectories just after their parent // so that the tree is not parsed multiple times while (!subDirs.IsEmpty()) { paths.InsertAfter(prevPos, subDirs.RemoveTail()); } } } }
void COpenDirHelper::RecurseAddDir(CString path, CAtlList<CString>* sl) { WIN32_FIND_DATA fd = {0}; HANDLE hFind = FindFirstFile(path + _T("*.*"), &fd); if(hFind != INVALID_HANDLE_VALUE) { do { CString f_name = fd.cFileName; if((fd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) && (f_name!=_T(".")) && (f_name!=_T(".."))) { CString fullpath = path + f_name; if(fullpath[fullpath.GetLength()-1] != '\\') { fullpath += '\\'; } sl->AddTail(fullpath); RecurseAddDir(fullpath, sl); } else { continue; } } while(FindNextFile(hFind, &fd)); FindClose(hFind); } }