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

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.     }  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值