void CMainFrame::BrowseDir(CString &strDir) { //定义查找文件对象 CFileFind cff; CString szDir = strDir; //当前文件 CString str; //当为根目录时,最右侧为'\' if(szDir.Right(1) != "\\") szDir += "\\"; //所有文件 szDir += _T("*.*"); BOOL bResult = cff.FindFile(szDir); while(bResult) { bResult = cff.FindNextFile(); if(cff.IsDirectory() && !cff.IsDots()) { //如果是一个子目录,用递归继续往深一层找 m_strPath=cff.GetFilePath(); BrowseDir(m_strPath); } else if(!cff.IsDirectory() && !cff.IsDots()) { //打开当前访问的文件获取文件大小等信息 str.Format(L"%s",cff.GetFilePath()); m_strFN.Format(L"%s",cff.GetFileName()); if(str.Right(3)=="mp3"||str.Right(3)=="mP3"|| str.Right(3)=="Mp3"||str.Right(3)=="MP3") { HANDLE hFile=::CreateFile(str,GENERIC_READ,FILE_SHARE_READ,NULL, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); DWORD fileSize=::GetFileSize(hFile,NULL); ReagTag(hFile,fileSize,m_tagID1,0); //添加数据库中 CSongRecordset songDb; AddToDb(songDb,m_tagID1); } } //置空 str=""; } cff.Close();//关闭 } 我封装了一个函数用来收集文件夹下的MP3,当调试时,strDir为"E:\新建文件夹 (3)"时,为什么cff.IsDots()会为1,按道理应该为0啊.
文件遍历
最新推荐文章于 2022-04-29 10:09:37 发布