void InformApp::FindExtensions(void) { m_extensions.clear(); for (int i = 0; i < 2; i++) { CString path; switch (i) { case 0: path.Format("%s\\Internal\\Extensions\\*.*",(LPCSTR)GetAppDir()); break; case 1: path.Format("%s\\Inform\\Extensions\\*.*",(LPCSTR)GetHomeDir()); break; default: ASSERT(FALSE); break; } CFileFind find; BOOL finding = find.FindFile(path); while (finding) { finding = find.FindNextFile(); if (!find.IsDots() && find.IsDirectory()) { CString author = find.GetFileName(); if (author == "Reserved") continue; if ((author.GetLength() > 0) && (author.GetAt(0) == '.')) continue; path.Format("%s\\*.*",(LPCSTR)find.GetFilePath()); CFileFind find; BOOL finding = find.FindFile(path); while (finding) { finding = find.FindNextFile(); if (!find.IsDirectory()) { CString ext = ::PathFindExtension(find.GetFilePath()); if (ext.CompareNoCase(".i7x") == 0) m_extensions.push_back(ExtLocation(author,find.GetFileTitle(),(i == 0),find.GetFilePath())); else if (ext.IsEmpty() && (i == 1)) { // Rename an old-style extension (with no file extension) to end with ".i7x" CString newPath = find.GetFilePath(); newPath.Append(".i7x"); if (::MoveFile(find.GetFilePath(),newPath)) m_extensions.push_back(ExtLocation(author,find.GetFileTitle(),(i == 0),newPath)); } } } find.Close(); } } find.Close(); } std::sort(m_extensions.begin(),m_extensions.end()); }
BOOL CMyUtils::DeleteDir(LPCTSTR lpDirPath) { CFileFind finder; BOOL bFind; TCHAR strFindPath[MAX_PATH]; _stprintf(strFindPath, _T("%s\\*"), lpDirPath); bFind = finder.FindFile(strFindPath); while (bFind) { bFind = finder.FindNextFile(); if (!finder.IsDirectory()) { if (!DeleteFile(finder.GetFilePath())) { finder.Close(); return FALSE; } } else if (!finder.IsDots()) { if (!DeleteDir(finder.GetFilePath())) { finder.Close(); return FALSE; } } } finder.Close(); return RemoveDirectory(lpDirPath); }
BOOL FileUtils::rmDir(string dirName) { char sTempFileFind[MAX_PATH] = ""; sprintf_s(sTempFileFind, "%s\\*.*", dirName.c_str()); CFileFind tempFind; BOOL isFinded = tempFind.FindFile(sTempFileFind); while (isFinded) { isFinded = tempFind.FindNextFile(); /* * 跳过 每个文件夹下面都有的两个特殊子文件夹: * (1) . 表示本文件夹自己 * (2) .. 表示本文件夹的父文件夹 */ if (!tempFind.IsDots()) { char tempFileOrDir[MAX_PATH] = ""; sprintf_s(tempFileOrDir, "%s\\%s", dirName.c_str(), tempFind.GetFileName().GetBuffer(MAX_PATH)); if (tempFind.IsReadOnly()) ::SetFileAttributes(tempFileOrDir, FILE_ATTRIBUTE_NORMAL); if (tempFind.IsDirectory()) rmDir(tempFileOrDir); else ::DeleteFile(tempFileOrDir); } } tempFind.Close(); return ::RemoveDirectory(dirName.c_str()); }
void CSkinManager::GetSkinList(CStringArray &skins) { CFileFind finder; CString dir = CMyUtility::GetCurDir(); CString strSkins; strSkins.Format(_T("%s\\skins\\*.*"), dir); BOOL bFind = finder.FindFile(strSkins); if(!bFind) return; while(bFind) { bFind = finder.FindNextFile(); if(finder.IsDots()) continue; if(finder.IsDirectory()) { skins.Add(finder.GetFileName()); continue; } } finder.Close(); }
bool CTestList::AddFilesFromPath( LPCTSTR pcszPath, HTREEITEM htreeParent ) { CString strPath( pcszPath ); strPath += _T("\\*.*"); CFileFind finder; BOOL bFound = finder.FindFile( strPath ); while( bFound ) { bFound = finder.FindNextFile(); if( !finder.IsDots() ) { CString strName( finder.GetFileName() ); if( strName.Find( _T(".html") ) != -1 || finder.IsDirectory() ) { TVITEM tvi; TVINSERTSTRUCT tvins; tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM; UINT uItem = m_arrFile.GetSize(); const CString strFilePath( finder.GetFilePath() ); m_arrFile.Add( strFilePath ); // Set the text of the item. tvi.pszText = (LPTSTR)(LPCTSTR)strName; tvi.cchTextMax = strName.GetLength(); tvi.iImage = tvi.iSelectedImage = 0; tvi.lParam = (LPARAM) uItem; tvins.item = tvi; tvins.hInsertAfter = TVI_LAST; tvins.hParent = htreeParent; // // Add the item to the tree-view control. HTREEITEM hTree = (HTREEITEM)m_treeList.SendMessage( TVM_INSERTITEM, 0, (LPARAM) (LPTVINSERTSTRUCT) &tvins); if( strFilePath == m_strLastLoaded ) { PostMessage( WM_MY_FIRST_SELECT, (WPARAM)hTree, 0 ); } if( finder.IsDirectory() ) { CString strPath( pcszPath ); strPath += _T("\\"); strPath += finder.GetFileName(); AddFilesFromPath( strPath, hTree ); } } } } return false; }
void CTestPage::freshSphLib() { DataBase db; BOOL bTraining = FALSE; db.ResetTable(_T("SpeechLib"),bTraining); //CStringArray* idArray = db.GetAllUserInfo(_T("UserId")); CString SpeechDir = _T("F:\\SpeechDirectory"); CString UserId,WavName,SphPath; CFileFind finder; UserId = _T("Test"); SphPath = SpeechDir + _T("\\") + UserId + _T("\\") + _T("*.wav"); BOOL res = finder.FindFile(SphPath); while(res){ res = finder.FindNextFile(); if(finder.IsDots()||finder.IsDirectory()) continue; WavName = finder.GetFileName(); db.InsertSpeechLib(UserId,WavName); } finder.Close(); }
////////////////////////////////////////////////////////////////////////// //递归删除文件夹 ////////////////////////////////////////////////////////////////////////// BOOL RecursiveRemoveFolder(CString strFolderPath,BOOL bRecursive) { CFileFind finder; CString strPath; BOOL bFound; if (strFolderPath.ReverseFind('\\') != 0) strFolderPath.Append(L"\\*.*"); bFound = finder.FindFile(strFolderPath); while(bFound) { bFound = finder.FindNextFile(); strPath = finder.GetFilePath(); if (finder.IsDots()) continue; else if (finder.IsDirectory() && bRecursive) RecursiveRemoveFolder(strPath,bRecursive); else { ::SetFileAttributes(strPath,FILE_ATTRIBUTE_NORMAL); ::DeleteFile(strPath); } } finder.Close(); return ::RemoveDirectory(strFolderPath); }
void CUpdateMgr::RestoreFile(wstring strRestorePath,wstring wsCurDirectory) { CFileFind fileFinder; CString filePath ;//= strRestorePath.c_str() + _T("//*.*"); filePath.Format(_T("%s\\*.*"),strRestorePath.c_str()); BOOL bFinished = fileFinder.FindFile(filePath); wstring wsDestfile; wstring wsRestoreFile; while(bFinished) //每次循环对应一个类别目录 { bFinished = fileFinder.FindNextFile(); if(fileFinder.IsDirectory() && !fileFinder.IsDots()) //若是目录则递归调用此方法 { // BayesCategoryTest(bt, fileFinder.GetFilePath()); } else //再判断是否为txt文件 { //获取文件类型 CString fileName = fileFinder.GetFileName(); if(fileName.Right(4).CompareNoCase(_T("_BAK")) == 0) { wsRestoreFile = strRestorePath + L"\\" + fileName.GetBuffer(0); wsDestfile = wsCurDirectory + L"\\" + fileName.Left(fileName.GetLength()-4).GetBuffer(0); BOOL bret = CsysFile::Copy(wsRestoreFile,wsDestfile); if (FALSE == bret) { g_Logger.Error(__FILE__,__LINE__,"还原文件失败 restore %s to %s",ws2s(wsRestoreFile).c_str(),ws2s(wsDestfile).c_str()); } } } } }
BOOL directoryDelete( LPCTSTR lpstrDir) { CFileFind cFinder; CString csPath; BOOL bWorking; try { csPath.Format( _T( "%s\\*.*"), lpstrDir); bWorking = cFinder.FindFile( csPath); while (bWorking) { bWorking = cFinder.FindNextFile(); if (cFinder.IsDots()) continue; if (cFinder.IsDirectory()) directoryDelete( cFinder.GetFilePath()); else DeleteFile( cFinder.GetFilePath()); } cFinder.Close(); return RemoveDirectory( lpstrDir); } catch (CException *pEx) { cFinder.Close(); pEx->Delete(); return FALSE; } }
BOOL CEncryptFile::DecryptDir(CString strKey, CString strSrcDir, CString strDstDir, CProgressCtrl *pCtal) { //AfxMessageBox("创建文件夹"+target); CFileFind finder; CString stPath; BOOL re = FALSE; stPath.Format(_T("%s/*.*"), strSrcDir); BOOL bWorking = finder.FindFile(stPath); while (bWorking) { bWorking = finder.FindNextFile(); if (finder.IsDirectory() && !finder.IsDots())//是文件夹 而且 名称不含 . 或 .. { //递归解密+"/"+finder.GetFileName() DecryptDir(strKey, finder.GetFilePath(), strDstDir + _T("\\") + finder.GetFileName(), pCtal); } else//是文件 则直接解密 { CString stSrcFile = finder.GetFilePath(); BOOL result = (GetFileAttributes(stSrcFile) & FILE_ATTRIBUTE_DIRECTORY); if (!result) { re = DecryptFile(strKey, finder.GetFilePath(), strDstDir + _T("\\") + finder.GetFileName()); pCtal->StepIt(); } } } return TRUE; }
/*================================================================= * Function ID : SMT_GetAllFileName * Input : void * Output : void * Author : * Date : 2006 2 * Return : void * Description : 得到所有文件名 * Notice : *=================================================================*/ void CSmartCommunicationDlg::SMT_GetAllFileName(vector<CString>& VFileName) { CString szDir=m_DealPath; CString strFile; CFileFind ff; if(szDir.Right(1)!= "\\") { szDir+="\\"; } szDir+= "*.*"; BOOL res=ff.FindFile(szDir); while(res) { res=ff.FindNextFile(); strFile=ff.GetFileName(); if(ff.IsDirectory() &&!ff.IsDots()) { continue; } if( strFile=="." || strFile=="..") { continue; } VFileName.push_back(strFile); } ff.Close(); return ; }
void Utils::DeletePath(CString sPath) { CFileFind tempFind; bool IsFinded = tempFind.FindFile(sPath + "\\*.*"); while (IsFinded) { IsFinded = tempFind.FindNextFile(); //当这个目录中不含有.的时候,就是说这不是一个文件。 if (!tempFind.IsDots()) { char sFoundFileName[200]; strcpy(sFoundFileName,tempFind.GetFileName().GetBuffer(200)); //如果是目录那么删除目录 if (tempFind.IsDirectory()) { char sTempDir[200]; sprintf(sTempDir,"%s\\%s",sPath,sFoundFileName); DeletePath(sTempDir); //其实真正删除文件的也就这两句,别的都是陪衬 } //如果是文件那么删除文件 else { char sTempFileName[200]; sprintf(sTempFileName,"%s\\%s",sPath,sFoundFileName); DeleteFile(sTempFileName); } } } tempFind.Close(); RemoveDirectory(sPath); }
//日志文件清理 void CWriteLogThread::CheckCleanupFileLogFile() { if(m_nLogFileCleanupDate == 0) { return; } COleDateTime time1,time2; COleDateTimeSpan time3; time2 = COleDateTime::GetCurrentTime(); int nYear,nMonth,nDate; sscanf(m_strLastCleanupLogFileDate, "%d:%d:%d",&nYear,&nMonth,&nDate); time1.SetDate(nYear,nMonth,nDate); time3 = time2 - time1; int nRunData = time3.GetDays(); //程序连续运行m_nLogFileCleanupDate天进行一次日志文件清理,保存前一天的日志 //m_nLogFileCleanupDate可以调用SetLogFileCleanupDate()函数设置 if(nRunData >= m_nLogFileCleanupDate) // { m_strLastCleanupLogFileDate = CTime::GetCurrentTime().Format("%Y:%m:%d"); CFileFind tempFileFind; CString szDir = m_strAppLogDir; CString strTitle; CFile file; if(szDir.Right(1) != _T("\\")) { szDir += _T("\\"); } szDir += _T("*.txt"); BOOL res = tempFileFind.FindFile(szDir); CString strYesterdayLogName; CTime time =CTime::GetCurrentTime() - CTimeSpan(1,0, 0,0); strYesterdayLogName = time.Format("%Y%m%d"); //前一天的日期 CString strDeleteFilePath; while( res ) { res = tempFileFind.FindNextFile(); if(!tempFileFind.IsDirectory() && !tempFileFind.IsDots()) { strTitle = tempFileFind.GetFileName(); if(strTitle.Find(strYesterdayLogName) == -1) //只保留前一天的日志文件 { //删除txt文件 strDeleteFilePath.Format("%s\\%s",m_strAppLogDir,strTitle); CFile::Remove(strDeleteFilePath);//删除文件 } } } tempFileFind.Close(); } }
BOOL CDirTreeCtrl::BuildTree(HTREEITEM hParent,LPCTSTR strPath) { CFileFind find; HTREEITEM parent; CString strTemp = strPath; BOOL bFind; if ( strTemp.Right(1) == _T('\\') ){ strTemp += _T("*.*"); }else{ strTemp += _T("\\*.*"); } bFind = find.FindFile( strTemp ); while ( bFind ) { bFind = find.FindNextFile(); if ( find.IsDirectory()){ if(!find.IsDots()){ parent = AddItem1(hParent, find.GetFilePath(), find.GetFileName()); BuildTree(parent, find.GetFilePath()); } }else{ AddItem1(hParent, find.GetFilePath(), find.GetFileName()); } } return TRUE; }
void MusicUtils::EmptyDir(CString Dir) { CFileFind finder; CFile cfile; CString Add=L"\\*"; CString DirSpec=Dir+Add; //???????????? BOOL bWorking = finder.FindFile(DirSpec); while (bWorking) { bWorking = finder.FindNextFile(); if(!finder.IsDots()) //???????? { if(finder.IsDirectory()) //???????? { CString strDirectory = finder.GetFilePath(); if(_rmdir((const char*)(LPSTR)(LPCTSTR)strDirectory)==-1) { EmptyDir(strDirectory); } bWorking = finder.FindFile(DirSpec); } else //??????? { cfile.Remove(finder.GetFilePath()); } } } finder.Close(); }
void MusicUtils::ScanFile(CString Dir,CArray<CString,CString&>& filearray,CString filetype) { CFileFind finder; CString Add=L"\\*"; CString DirSpec=Dir+Add; //补全要遍历的文件夹的目录 BOOL bWorking = finder.FindFile(DirSpec); while (bWorking) { bWorking = finder.FindNextFile(); if(!finder.IsDots()) //扫描到的不是节点 { if(finder.IsDirectory()) //扫描到的是文件夹 { CString strDirectory = finder.GetFilePath(); ScanFile(strDirectory,filearray,filetype); //递归调用ScanFile() } else //扫描到的是文件 { CString strFile = finder.GetFilePath(); // 得到文件的全路径 CString ext = GetFileTitleFromFileName(strFile).MakeLower(); if (ext==CString("bmp")) { filearray.Add(strFile); } //进行一系列自定义操作 } } } finder.Close(); }
BOOL CDirTreeCtrl::FindSubDir( LPCTSTR strPath) { // // Are there subDirs ? // CFileFind find; CString strTemp = strPath; BOOL bFind; if ( strTemp[strTemp.GetLength()-1] == '\\' ) strTemp += _T("*.*"); else strTemp += _T("\\*.*"); bFind = find.FindFile( strTemp ); while ( bFind ) { bFind = find.FindNextFile(); if ( find.IsDirectory() && !find.IsDots() ) { return TRUE; } if ( !find.IsDirectory() && m_bFiles && !find.IsHidden() ) return TRUE; } return FALSE; }
void CDirectoryTreeCtrl::AddSubdirectories(HTREEITEM hRoot, CString strDir) { strDir += _T("*.*"); CFileFind finder; BOOL bWorking = finder.FindFile(strDir); while (bWorking) { bWorking = finder.FindNextFile(); if (finder.IsDots()) continue; if (finder.IsSystem()) continue; if (!finder.IsDirectory()) continue; CString strFilename = finder.GetFileName(); int iIdx; if ((iIdx = strFilename.ReverseFind('\\')) != -1) strFilename = strFilename.Mid(iIdx + 1); AddChildItem(hRoot, strFilename); } finder.Close(); }
void CDirstatDoc::RecursiveUserDefinedCleanup(const USERDEFINEDCLEANUP *udc, const CString& rootPath, const CString& currentPath) { // (Depth first.) CFileFind finder; BOOL b = finder.FindFile(currentPath + _T("\\*.*")); while(b) { b = finder.FindNextFile(); if((finder.IsDots()) || (!finder.IsDirectory())) { continue; } if(GetWDSApp()->IsVolumeMountPoint(finder.GetFilePath()) && !GetOptions()->IsFollowMountPoints()) { continue; } if(GetWDSApp()->IsFolderJunction(finder.GetFilePath()) && !GetOptions()->IsFollowJunctionPoints()) { continue; } RecursiveUserDefinedCleanup(udc, rootPath, finder.GetFilePath()); } CallUserDefinedCleanup(true, udc->commandLine, rootPath, currentPath, udc->showConsoleWindow, true); }
bool CDirectoryTreeCtrl::HasSubdirectories(CString strDir) { strDir += _T("*.*"); CFileFind finder; BOOL bWorking = finder.FindFile(strDir); while (bWorking) { bWorking = finder.FindNextFile(); if (finder.IsDots()) continue; if (finder.IsSystem()) continue; if (!finder.IsDirectory()) continue; finder.Close(); return true; } finder.Close(); return false; }
void DirRecurs(LPCTSTR pstr) { CFileFind finder; CString sz_wildcard(pstr); sz_wildcard += _T("\\*.*"); BOOL bResult = finder.FindFile(sz_wildcard); while (bResult) { bResult = finder.FindNextFile(); //skip . and .. files; otherwise, recur infinitely! CString temp = finder.GetFilePath(); cout << (LPCTSTR)temp << endl; if (finder.IsDots()) continue; //if it's a directory , recursively search it if (finder.IsDirectory()) { CString str = finder.GetFilePath(); //cout << (LPCTSTR)str << endl; //DirRecurs(str); } } finder.Close(); }
void MFCFileFind(CString strPath){ CFileFind find; BOOL bRet = find.FindFile(strPath+"/*.*"); //FindFile只能获取到是否有该文件 while(bRet){ //得到当前文件信息,并返回下一个文件是否存在 bRet = find.FindNextFile(); CString strName=find.GetFileName(); if(find.IsDirectory()){ printf("目录:%s\n",strName); //CString 直接可以在%s中打印 #if 1 if(!find.IsDots()){ MFCFileFind(strPath+"/"+strName); //也可以使用GetFilePath } #endif } else{ printf("文件:%s\n",strName); } } find.Close(); }
void CMyExplorerDoc::GetChildFolders(CStringArray *strFolderList, CString strParentFolder) { // MFC에서 지원되는 파일 검색 객체 CFileFind ff; if (strParentFolder.Right(1) != '\\') { strParentFolder += '\\'; } strParentFolder += "*.*"; // 주어진 경로의 파일을 찾음 if (ff.FindFile(strParentFolder) == TRUE) { BOOL bFlag = TRUE; while(bFlag == TRUE) { // 파일이 존재할 경우 다음 파일을 찾을수 // 있도록 해준다. bFlag = ff.FindNextFile(); // 파일이 디렉토리이면 0이 아닌 수를 리턴 // 파일이 '.' 또는 '..'이면 0이 아닌 수를 리턴 if (ff.IsDirectory() && !ff.IsDots()) strFolderList->Add(ff.GetFileName()); } } ff.Close(); }
void CNifConvertDlg::parseDir(CString path, set<string>& directories, bool doDirs) { CFileFind finder; BOOL result(FALSE); result = finder.FindFile(path + _T("\\*.*")); while (result) { result = finder.FindNextFileW(); if (finder.IsDots()) continue; if (finder.IsDirectory() && doDirs) { CString newDir(finder.GetFilePath()); CString tDir = newDir.Right(newDir.GetLength() - newDir.Find(_T("\\Textures\\")) - 1); directories.insert(CStringA(tDir).GetString()); parseDir(newDir, directories); } else if (!finder.IsDirectory() && !doDirs) { CString newDir(finder.GetFilePath()); CString tDir = newDir.Right(newDir.GetLength() - path.GetLength() - 1); directories.insert(CStringA(tDir).GetString()); } } }
int KGObjectPropertyEditDlg::GetChildPoint( HTREEITEM hParent, CString szPath, ENUM_CALL_TYPE nType ) { int nResult = false; int nRetCode = false; ASSERT(hParent); HTREEITEM hChild; KG_PROCESS_ERROR(szPath != ""); if (nType == TYPE_FIRST) { hChild = hParent; } else { hChild = m_treeObjectView.GetChildItem(hParent); } while (hChild) { CString strText = m_treeObjectView.GetItemText(hChild); if (strText.Right(1) != "\\") { strText += _T("\\"); } CFileFind file; BOOL bContinue = file.FindFile(szPath + strText + "*.*"); while (bContinue) { bContinue = file.FindNextFile(); if (file.IsDirectory() && !file.IsDots()) { m_treeObjectView.InsertItem(file.GetFileName(), hChild); } else if (file.GetFileName().Right(4) == ".ini") { char szName[MAX_TEXT]; strncpy( szName, file.GetFileName().GetBuffer(), sizeof(szName) ); szName[sizeof(szName) - 1] = '\0'; m_treeObjectView.InsertItem(szName, hChild); } } file.Close(); GetChildPoint(hChild, szPath + strText, TYPE_OTHER); hChild = m_treeObjectView.GetNextItem(hChild, TVGN_NEXT); } nResult = true; Exit0: return nResult; }
// ---------------------------------------------------------------------------- // void DefinitionReader::readFixtureDefinitions( LPCSTR directory ) { CFileFind finder; CString directory_search( directory ); directory_search.Append( "\\*" ); BOOL working = finder.FindFile( directory_search ); if ( !working ) throw StudioException( "Unable to find fixture definition directory '%s'", directory ); while ( working ) { working = finder.FindNextFile(); if ( finder.IsDots() ) continue; CString file_name = finder.GetFilePath(); if ( finder.IsDirectory() ) readFixtureDefinitions( file_name ); CString test_name( file_name ); if ( test_name.MakeLower().Find( ".xml" ) == -1 ) continue; // Check for definition file TiXmlDocument doc; if ( !doc.LoadFile( file_name ) ) throw StudioException( "Error reading fixture definition '%s'", file_name ); try { TiXmlElement* root = doc.FirstChildElement( "fixture_definitions" ); LPCSTR author = read_text_element( root, "author" ); LPCSTR version = read_text_element( root, "version" ); FixtureDefinitionPtrArray fixture_definitions = read_xml_list<FixtureDefinition>( root, "fixture" ); //DefinitionWriter writer; //writer.writeFixtureDefinition( file_name, author, version, fixture_definitions ); for ( FixtureDefinition* definition : fixture_definitions ) { definition->setSourceFile( file_name ); definition->m_author = author; definition->m_version = version; FixtureDefinition::addFixtureDefinition( definition ); delete definition; } } catch ( StudioException e ) { throw StudioException( "%s: %s", file_name, e.what() ); } } finder.Close(); }
void CDirTreeCtrl::DisplayPath(HTREEITEM hParent, LPCTSTR strPath) { // // Displaying the Path in the TreeCtrl // CFileFind find; CString strPathFiles = strPath; BOOL bFind; CSortStringArray strDirArray; CSortStringArray strFileArray; if ( strPathFiles.Right(1) != _T("\\") ) strPathFiles += _T("\\"); strPathFiles += _T("*.*"); bFind = find.FindFile( strPathFiles ); while ( bFind ) { bFind = find.FindNextFile(); if ( find.IsDirectory() && !find.IsDots() ) { strDirArray.Add( find.GetFilePath() ); } if ( !find.IsDirectory() && m_bFiles ) strFileArray.Add( find.GetFilePath() ); } strDirArray.Sort(); SetRedraw( FALSE ); CWaitCursor wait; for ( int i = 0; i < strDirArray.GetSize(); i++ ) { HTREEITEM hItem = AddItem( hParent, strDirArray.GetAt(i) ); if ( FindSubDir( strDirArray.GetAt(i) ) ) InsertItem( _T(""), 0, 0, hItem ); } if ( m_bFiles ) { strFileArray.Sort(); for (int i = 0; i < strFileArray.GetSize(); i++ ) { HTREEITEM hItem = AddItem( hParent, strFileArray.GetAt(i) ); } } SetRedraw( TRUE ); }
bool CFileUtil::ScanDirectory( const CString &path,const CString &fileSpec, CStringArray &files, bool recursive/*=true*/, ScanDirectoryUpdateCallBack updateCB /*= NULL */ ) { CStringArray dirs; CString searchname; CFileFind find; files.RemoveAll(); dirs.Add(path); BOOL bRet; while(dirs.GetSize()>0) { if (dirs[0][dirs[0].GetLength()-1] == '\\') { searchname = dirs[0] + fileSpec; } else { searchname = dirs[0] + "\\" + fileSpec; } dirs.RemoveAt(0); bRet = find.FindFile (searchname,0); if(!bRet) { continue; } do { bRet = find.FindNextFile (); if(find.IsDots()) { //忽略.和..文件 continue; } if(find.IsDirectory ()) { //目录 files.Add(find.GetFilePath()); if (updateCB) { updateCB(find.GetFilePath()); } continue; } else { //文件,此处不处理 } }while(bRet) ; } return true; }
void DelTB(char* pTb) { char loc[256]; char locfile[256]; CFileFind finder; strcpy(locfile,pTb); //<---locfile为所要删除的table的目录 strcpy(loc,locfile); //<---locfile为所要删除的table的目录 strcat(locfile , ".idx"); //<---该目录下所有的文件 int bWorking = finder.FindFile(locfile); while(bWorking) { bWorking = finder.FindNextFile(); if (finder.IsDots()) continue; if (!finder.IsDirectory()) { CString str = finder.GetFilePath(); CFile::Remove( str ); } } finder.Close(); strcat(loc , ".dbf"); //<---该目录下所有的文件 bWorking = finder.FindFile(loc); while(bWorking) { bWorking = finder.FindNextFile(); if (finder.IsDots()) continue; if (!finder.IsDirectory()) { CString str = finder.GetFilePath(); CFile::Remove( str ); } } finder.Close(); }
BOOL PathManager::CopyDir(CString strSrcPath, CString strDstPath) { // 创建目标文件夹 if (strSrcPath.Right(1) == "\\") { strSrcPath = strSrcPath.Left(strSrcPath.GetLength() - 1); } if (strDstPath.Right(1) == "\\") { strDstPath = strDstPath.Left(strDstPath.GetLength() - 1); } CreateDirectory(strDstPath,NULL); CFileFind finder; // 打开指定的文件夹进行搜索 BOOL bWorking = finder.FindFile(strSrcPath + "\\" + "*.*"); while(bWorking) { // 从当前目录搜索文件 bWorking = finder.FindNextFile(); CString strFileName = finder.GetFileName(); CString strSrc = strSrcPath + "\\" + strFileName; CString strDst = strDstPath + "\\" + strFileName; // 判断搜索到的是不是"."和".."目录 if(!finder.IsDots()) { // 判断搜索到的目录是否是文件夹 if(finder.IsDirectory()) { // 如果是文件夹的话,进行递归 if(!CopyDir(strSrc, strDst)) { return false; } } else { // 如果是文件,进行复制 if(!CopyFile(strSrc, strDst, FALSE)) { return false; } } } } return true; }