嵌套目录查找文件查询。要改递归。需要自己再修改下

void CDataForwardService::list_files(list<CString> & files_arr, LPCTSTR pstr,bool isFiles /*= false*/)
{
CFileFind finder;
CStringW strWildcard(pstr);
strWildcard += _T("\\*.*");
BOOL bWorking = finder.FindFile(strWildcard);
while (bWorking) {
bWorking = finder.FindNextFile();
if (finder.IsDots()) {
continue;
}
if (finder.IsDirectory()) {
CStringW str = finder.GetFilePath();
//TRACE(_T("%s\n"), (LPCTSTR)str);
files_arr.push_back(str);
} else {
if (isFiles){
CStringW str = finder.GetFilePath();
files_arr.push_back(str);
}
}
}
finder.Close();

}

上面也是转载加修改

下面是转载


  1. void DealFileInterfaceImpl::RecursionToFind(CString strTempPath,FILELIST& sfilelist)  
  2. {  
  3.     CString strPath = strTempPath + ALL_FILE;  
  4.     CString strTmp = _T("");  
  5.     TARGETFILE sFile;  
  6.     char* s_char = NULL;  
  7.   
  8.     CFileFind tempFind;  
  9.     BOOL bFound;  
  10.     bFound=tempFind.FindFile(strPath);  
  11.   
  12.     while(bFound)                           //遍历所有文件  
  13.     {  
  14.         bFound=tempFind.FindNextFile();           
  15.         if(tempFind.IsDots())               //如果找到的是当前或者上层目录则结束本次查找  
  16.         {  
  17.             continue;  
  18.         }                     
  19.   
  20.         if(tempFind.IsDirectory())          //找到的是文件夹,则遍历该文件夹下的文件  
  21.         {  
  22.             //USES_CONVERSION;  
  23.             //strTmp = tempFind.GetFileName();  
  24.             //s_char = W2A(strTmp);  
  25.             //sFile.strFileName = s_char;     
  26.             strTmp=tempFind.GetFilePath();  
  27.             //s_char=W2A(strTmp);   
  28.             //sFile.strFilePath = s_char;  
  29.             //sfilelist.push_back(sFile);  
  30.             RecursionToFind(strTmp,sfilelist);//递归调用  
  31.         }  
  32.         else  
  33.         {  
  34.             USES_CONVERSION;  
  35.   
  36.             strTmp = tempFind.GetFileName();  
  37.             s_char = W2A(strTmp);  
  38.             sFile.strFileName = s_char;  
  39.   
  40.             strTmp=tempFind.GetFilePath();  
  41.             s_char=W2A(strTmp);   
  42.             sFile.strFilePath = s_char;  
  43.   
  44.             boost::hash<std::string> string_hash;  
  45.             std::string strFileID = s_char;  
  46.             sFile.ulFilesID = string_hash(strFileID);  
  47.   
  48.             s_char=W2A(CMD5Checksum::GetMD5(strTmp));  
  49.             sFile.strFilesMD5 = s_char;  
  50.   
  51.             sfilelist.push_back(sFile);  
  52.         }  
  53.     }  
  54.     tempFind.Close();  
  55. }  


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值