CFileFind finder;
BOOL blNotEmpty = finder.FindFile(strDir + _T("\\*.*"));
while (blNotEmpty)
{
blNotEmpty = finder.FindNextFile();
CString filename = finder.GetFilePath();
std::cout << filename << std::endl;
if (finder.IsDots())
continue;
if (!finder.IsDirectory())
{
files.push_back(filename);
}
else
{
if (!finder.IsTemporary())
{
GetFileNames(files, finder.GetFilePath()+_T("/"));
}
}
}
默認是C盤
uj5u.com熱心網友回復:
system("dir /b /a-d c:\\*.* >d:\\allfiles.txt");//讀檔案d:\\allfiles.txt的內容即C:\\下所有檔案的名字
system("dir /b /a-d /s c:\\*.* >d:\\allfilesinsub.txt");
//讀檔案d:\\allfilesinsub.txt的內容即C:\\下所有檔案的名字包含子目錄
system("dir /b /ad c:\\*.* >d:\\alldirs.txt");
//讀檔案d:\\alldirs.txt的內容即C:\\下所有子目錄的名字
請記住,能用shell命令獲取檔案、檔案夾資訊或者操作檔案、檔案夾最好用shell命令獲取或者操作,而不要用各種API獲取或者操作,因為當遇到非法檔案夾名或非法檔案名或非法檔案長度、非法檔案日期、壓縮檔案、鏈接檔案、稀疏檔案……等各種意料之外的情況時,API會處理的不全面或陷入死回圈,而shell命令不會。
如果嫌system黑視窗一閃,將system("...")替換為WinExec("cmd /c ...",SW_HIDE);
uj5u.com熱心網友回復:
CString filename = finder.GetFilePath();CStringA filenameA = (CString)filename;
std::cout << filenameA << std::endl;
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/122959.html
標籤:基礎類
下一篇:求助啊!!!
