http://blog.csdn.net/yearafteryear/archive/2010/01/14/5188924.aspx
- GetAllFileInfo( LPCWSTR fileTypePath)
- {
- WIN32_FIND_DATA AlbumData;
- HANDLE hSearch;
- bool bFinished= false ;
- CString Str=fileTypePath, strTemp;
- //开始按搜索条件搜索
- CString strsearch = Str;
- strsearch += L"//*" ;
- hSearch=FindFirstFile(strsearch,&AlbumData);
- if (hSearch==INVALID_HANDLE_VALUE)
- {
- return ;
- }
- //开始递归搜索
- do
- {
- //对当前目录和上一级目录进行判断过滤
- if (wcscmp(AlbumData.cFileName, L "." ) == 0 || wcscmp(AlbumData.cFileName, L ".." ) == 0)
- {
- continue ;
- }
- if (AlbumData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY) //目录
- {
- CString strFilePathTemp = Str;
- strFilePathTemp += L"//" ;
- strFilePathTemp += AlbumData.cFileName;//获得此目录的绝对路径进行递归搜索
- GetAllFileInfo(strFilePathTemp);
- }
- else //找到文件进行判断是否是目标文件类型
- {
- CString strTemp = AlbumData.cFileName, strsuffix;
- strsuffix = strTemp.Mid(strTemp.ReverseFind(L'.' )+1); //文件的后缀名
- if (wcscmp(strsuffix, L "mp3" ) == 0 || wcscmp(strsuffix, L "wav" ) == 0 || wcscmp(strsuffix, L "wma" ) == 0)
- {
- CString strs = Str;
- strs += L"//" ;
- strs += AlbumData.cFileName;
- if (nTotalFileCount<MAXNUM)
- {
- PathAndFileName[nTotalFileCount]=strs;
- nTotalFileCount++;
- }
- else
- {
- AfxMessageBox(TEXT("内存有限请不要再添加" ));
- break ;
- }
- }
- }
- } while (FindNextFile(hSearch,&AlbumData));
- if (!FindClose(hSearch))
- {
- AfxMessageBox(_T("关闭查找句柄失败" ));
- }
- }