首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

MFC遍历文件夹,该怎么处理

2013-03-28 
MFC遍历文件夹本帖最后由 tmwanly 于 2013-03-26 10:35:45 编辑void dfsFolder(string folderPath, ofstre

MFC遍历文件夹
本帖最后由 tmwanly 于 2013-03-26 10:35:45 编辑


void dfsFolder(string folderPath, ofstream &fout)
{
_finddata_t FileInfo;
string strfind = folderPath + "\\*";
long Handle = _findfirst(strfind.c_str(), &FileInfo);

if (Handle == -1L)
{
cerr << "can not match the folder path" << endl;
exit(-1);
}
do{
//判断是否有子目录
if (FileInfo.attrib & _A_SUBDIR)    
{
if( (strcmp(FileInfo.name,".") != 0 ) &&(strcmp(FileInfo.name,"..") != 0))   
{
string newPath = folderPath + "\" + FileInfo.name;
dfsFolder(newPath, fout);
}
}
else  
{
fout << folderPath << "\" << FileInfo.name  << " ";
}
}while (_findnext(Handle, &FileInfo) == 0);

_findclose(Handle);
fout.close();
}

该怎么调用呢,folderPath是文件,那fout是什么呢,起什么作用的,没看明白,求解释
[解决办法]




引用:
引用:引用:不知道怎么打开文件下的子文件

string newPath = folderPath + "\" + FileInfo.name;
                dfsFolder(newPath, fout);

newPath 不就是子文件夹路径了么 这个是递归调用,你应……


抱歉  fout解释错了

你要遍历C盘的windows 把便利的到所有文件名保存到c:\1.txt里
ofstream file;
file.open(L"c:\\1.txt");
string strFilePath = "c:\\windows";

dfsFolder(strFilePath,out);

就是这样 你那个if (Handle == -1L) 看看是不是你参数传的有问题

热点排行
Bad Request.