EVC 递归添加文件夹下面的文件

来源:互联网 发布:电脑格式化后数据恢复 编辑:程序博客网 时间:2024/09/21 07:52

http://blog.csdn.net/yearafteryear/archive/2010/01/14/5188924.aspx

 

 

  1. GetAllFileInfo(LPCWSTR fileTypePath)  
  2. {  
  3.     WIN32_FIND_DATA AlbumData;  
  4.     HANDLE  hSearch;  
  5.     bool bFinished=false;  
  6.     CString Str=fileTypePath, strTemp;  
  7.     //开始按搜索条件搜索  
  8.     CString strsearch = Str;  
  9.     strsearch += L"//*";  
  10.     hSearch=FindFirstFile(strsearch,&AlbumData);  
  11.   
  12.     if(hSearch==INVALID_HANDLE_VALUE)  
  13.     {  
  14.         return;  
  15.     }  
  16.     //开始递归搜索  
  17.     do   
  18.     {  
  19.         //对当前目录和上一级目录进行判断过滤  
  20.         if (wcscmp(AlbumData.cFileName, L".") == 0 || wcscmp(AlbumData.cFileName, L"..") == 0)  
  21.         {  
  22.             continue;  
  23.         }  
  24.           
  25.         if (AlbumData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY) //目录  
  26.         {  
  27.             CString strFilePathTemp = Str;  
  28.             strFilePathTemp += L"//";  
  29.             strFilePathTemp += AlbumData.cFileName;//获得此目录的绝对路径进行递归搜索  
  30.             GetAllFileInfo(strFilePathTemp);  
  31.         }  
  32.         else    //找到文件进行判断是否是目标文件类型  
  33.         {  
  34.   
  35.             CString strTemp = AlbumData.cFileName, strsuffix;  
  36.             strsuffix = strTemp.Mid(strTemp.ReverseFind(L'.')+1);   //文件的后缀名  
  37.             if (wcscmp(strsuffix, L"mp3") == 0 || wcscmp(strsuffix, L"wav") == 0 || wcscmp(strsuffix, L"wma") == 0)  
  38.             {  
  39.                 CString strs = Str;  
  40.                 strs += L"//";  
  41.                 strs += AlbumData.cFileName;      
  42.                 if(nTotalFileCount<MAXNUM)  
  43.                 {  
  44.                     PathAndFileName[nTotalFileCount]=strs;  
  45.                     nTotalFileCount++;    
  46.                 }  
  47.                 else  
  48.                 {  
  49.                     AfxMessageBox(TEXT("内存有限请不要再添加"));  
  50.                     break;  
  51.                 }  
  52.             }  
  53.         }  
  54.     } while(FindNextFile(hSearch,&AlbumData));  
  55.     if(!FindClose(hSearch))  
  56.     {  
  57.         AfxMessageBox(_T("关闭查找句柄失败"));  
  58.     }  

原创粉丝点击