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();
{
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();
}
上面也是转载加修改
下面是转载
- void DealFileInterfaceImpl::RecursionToFind(CString strTempPath,FILELIST& sfilelist)
- {
- CString strPath = strTempPath + ALL_FILE;
- CString strTmp = _T("");
- TARGETFILE sFile;
- char* s_char = NULL;
- CFileFind tempFind;
- BOOL bFound;
- bFound=tempFind.FindFile(strPath);
- while(bFound) //遍历所有文件
- {
- bFound=tempFind.FindNextFile();
- if(tempFind.IsDots()) //如果找到的是当前或者上层目录则结束本次查找
- {
- continue;
- }
- if(tempFind.IsDirectory()) //找到的是文件夹,则遍历该文件夹下的文件
- {
- //USES_CONVERSION;
- //strTmp = tempFind.GetFileName();
- //s_char = W2A(strTmp);
- //sFile.strFileName = s_char;
- strTmp=tempFind.GetFilePath();
- //s_char=W2A(strTmp);
- //sFile.strFilePath = s_char;
- //sfilelist.push_back(sFile);
- RecursionToFind(strTmp,sfilelist);//递归调用
- }
- else
- {
- USES_CONVERSION;
- strTmp = tempFind.GetFileName();
- s_char = W2A(strTmp);
- sFile.strFileName = s_char;
- strTmp=tempFind.GetFilePath();
- s_char=W2A(strTmp);
- sFile.strFilePath = s_char;
- boost::hash<std::string> string_hash;
- std::string strFileID = s_char;
- sFile.ulFilesID = string_hash(strFileID);
- s_char=W2A(CMD5Checksum::GetMD5(strTmp));
- sFile.strFilesMD5 = s_char;
- sfilelist.push_back(sFile);
- }
- }
- tempFind.Close();
- }