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盘

解决方案 »

  1.   

    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);
      

  2.   

    CString filename = finder.GetFilePath();
    CStringA filenameA = (CString)filename;
    std::cout << filenameA << std::endl;