vc++遍历某一个目录下的所有 目录和文件代码 BOOL GetFile(CString Path)...{ CStringList listPaths; CString strPath; CString strFolder; CStringList listFiles; int iFileCount=0; int PathLen=Path.GetLength(); CFileFind finder; BOOL bWorking; strPath.Format("%s/*.*", Path); do...{ bWorking = finder.FindFile(strPath); while(bWorking) ...{ bWorking = finder.FindNextFile(); //子目录获取 CString strFilePath = finder.GetFilePath(); if(finder.IsDots()) continue; if(finder.IsDirectory()) ...{ //文件路径获取这里获取到了 listPaths.AddHead(strFilePath); continue; } else ...{ int pos=strFilePath.ReverseFind('/'); SHFILEINFO sfi; if (::SHGetFileInfo (strFilePath, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(SHFILEINFO),SHGFI_USEFILEATTRIBUTES | SHGFI_DISPLAYNAME | SHGFI_TYPENAME |SHGFI_ICON|SHGFI_SMALLICON )) ...{ CString str; str.Format("%s/%s",strFilePath.Mid(0,pos),sfi.szDisplayName); listFiles.AddHead(str); //文件带路径的名字获取这里获取到了str iFileCount++; } } } if(listPaths.IsEmpty()) break; strFolder = listPaths.RemoveHead(); strPath = strFolder + "/*.*"; finder.Close(); }while(TRUE); return TRUE;}