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); }
/********************************************************************** * 函数名称: // DeleteRecord() * 功能描述: // 删除多余的log文件,保存的个数可以通过SetLogRecordCount改变 * 输入参数: // 无 * 输出参数: // 无 * 返 回 值: // 返回True * 其它说明: // 无 * 修改日期 版本号 修改人 修改内容 * ----------------------------------------------- * 2009/07/21 V1.0 ***********************************************************************/ BOOL CLogRecord::DeleteRecord() { CString strFile; CFileFind finder; BOOL bWorking; int nfileNum = 0; strFile.Format("%s\\*.log",m_strCurrentRecordPath); bWorking = finder.FindFile(strFile); while (bWorking) { bWorking = finder.FindNextFile(); nfileNum++; } finder.Close(); if(nfileNum >m_nRecordLogCount) { nfileNum = nfileNum-m_nRecordLogCount; bWorking = finder.FindFile(strFile); while (bWorking&&nfileNum) { bWorking = finder.FindNextFile(); nfileNum--; DeleteFile(finder.GetFilePath()); } } finder.Close(); return TRUE; }
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; } }
// 粉碎按钮消息 // void CTool::OnBnClickedShatter() { // TODO: 在此添加控件通知处理程序代码 // 如果文件路径不是有效的,则不做响应 CFileFind fileFind; if(!fileFind.FindFile(m_FilePath)) { MessageBox("不是有效的文件路径!", "提示", MB_OK); fileFind.Close(); // 关闭文件查找,释放资源 return; } fileFind.Close(); // 关闭文件查找,释放资源 // 设置文件属性(取消只读属性) if(!CSystemController::FileAttributesOperation(m_FilePath)) { MessageBox("文件属性设置失败!", "提示", MB_OK); return; } ::EnableWindow(m_Shatter, FALSE); // 粉碎按钮变灰色且不可用 // 创建线程,并返回句柄 HANDLE hThread = CreateThread(NULL, 0, MyShatterThread, this, 0, NULL); // 如果线程创建失败则返回 if(hThread == NULL) { MessageBox("线程创建错误!","提示",MB_OK); return; } }
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; }
BOOL CRegConfig::ExportReg(LPCTSTR pszFileName) { if (pszFileName == NULL) { return FALSE; } CWaitCursor wait; CFileFind find; if (find.FindFile(pszFileName)) { if (!DeleteFile(pszFileName)) { find.Close(); return FALSE; } } find.Close(); int nSectionLen = sizeof(g_chSection) / sizeof(g_chSection[0]); for (int i = 0; i < nSectionLen; ++i ) { if (!SaveRegToConfig(g_chSection[i], pszFileName)) return FALSE; } return TRUE; }
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 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(); }
int KGObjectPropertyEditDlg::GetRootPoint(CString szPath) { int nResult = false; int nRetCode = false; CFileFind file; BOOL bContinue = file.FindFile(szPath + "*"); KG_PROCESS_ERROR(szPath != ""); int temp = 0; while (bContinue) { bContinue = file.FindNextFile(); if (file.IsDirectory() && !file.IsDots()) { if (temp == 0) { m_treeRoot = m_treeObjectView.InsertItem(file.GetFileName()); temp = 1; } else { m_treeObjectView.InsertItem(file.GetFileName()); } } } nResult = true; Exit0: file.Close(); return nResult; }
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 ShowDB() { CFileFind finder; int iRowN = 0; int iNameLen = 0,iTemp = 0; std::cout<<"These are the databases !\n"; int bWorking = finder.FindFile("..\\Data\\*.*"); std::cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<'\n';//<---计32个字符 std::cout<<"| Database |"<<'\n'; std::cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<'\n';//<---计32个字符 while(bWorking) { bWorking = finder.FindNextFile(); if (finder.IsDots()) continue; if (finder.IsDirectory()) { iRowN++; CString str = finder.GetFileTitle(); iNameLen = str.GetLength(); std::cout <<"| "<< (LPCTSTR) str; for(iTemp = 29 - iNameLen;iTemp != 0;iTemp--) std::cout<<' '; std::cout <<"|"<<'\n'; } } std::cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<'\n';//<---计32个字符 std::cout<<"There are" <<iRowN<<" rows in the database!"; finder.Close(); }
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 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 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(); }
/*================================================================= * 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 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(); } }
void CTestPage::OnButtonTest() { // TODO: Add your control notification handler code here CString SpeakerId = _T("Test"); CString SpeechId; int index = cbx_TestSph.GetCurSel(); if(index==-1){ AfxMessageBox(_T("请先选择语音,再进行测试!如果没有相应的语音,则回到语音采集页进行语音采集。")); return; } cbx_TestSph.GetLBText(index,SpeechId); //m_SpeechId = SpeechId; CString SpeechDir = _T("F:\\SpeechDirectory"); CString SphPath = SpeechDir+_T("\\")+SpeakerId+_T("\\")+SpeechId; CFileFind finder; BOOL res = finder.FindFile(SphPath); if(!res){ AfxMessageBox(_T("找不到指定音频文件。语音库更新中...")); //更新语音库 freshSphLib(); AfxMessageBox(_T("语音库更新完毕!请重新点击\"测试\"按钮进行训练。")); return; } finder.Close(); AfxMessageBox(_T("测试成功!")); }
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 DelDB(char* pDb) { char loc[256]; char locfile[256]; CFileFind finder; strcpy(locfile,pDb); //<---所要删除的目录的路径 strcpy(loc,pDb); //<---所要删除的目录的路径 strcat(locfile , "\\*.*"); //<---该目录下所有的文件 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(); //删除空目录---> if( _rmdir( loc ) == 0 ) std::cout<<"Directory "<<loc<<" was successfully removed\n"; else std::cout<<"Can not remove database"<<loc<<"\n"; ResetDBinfo(); //<---删除数据库之后将全局路径重新设置 }
static void InitLanguages(const CString& rstrLangDir, bool bReInit = false) { static BOOL _bInitialized = FALSE; if (_bInitialized && !bReInit) return; _bInitialized = TRUE; CFileFind ff; bool bEnd = !ff.FindFile(rstrLangDir + _T("*.dll"), 0); while (!bEnd) { bEnd = !ff.FindNextFile(); if (ff.IsDirectory()) continue; TCHAR szLandDLLFileName[MAX_PATH]; _tsplitpath(ff.GetFileName(), NULL, NULL, szLandDLLFileName, NULL); SLanguage* pLangs = _aLanguages; if (pLangs){ while (pLangs->lid){ if (_tcsicmp(pLangs->pszISOLocale, szLandDLLFileName) == 0){ pLangs->bSupported = TRUE; break; } pLangs++; } } } ff.Close(); }
bool DeleteDirectory(const char *DirName)//如删除DeleteDirectory("c:\\aaa") { CFileFind tempFind; char tempFileFind[MAX_PATH]; sprintf(tempFileFind,"%s\\*.*",DirName); BOOL IsFinded=(BOOL)tempFind.FindFile(tempFileFind); while(IsFinded) { IsFinded=(BOOL)tempFind.FindNextFile(); if(!tempFind.IsDots()) { char foundFileName[MAX_PATH]; strcpy(foundFileName,tempFind.GetFileName().GetBuffer(MAX_PATH)); if(tempFind.IsDirectory()) { char tempDir[MAX_PATH]; sprintf(tempDir,"%s\\%s",DirName,foundFileName); DeleteDirectory(tempDir); } else { char tempFileName[MAX_PATH]; sprintf(tempFileName,"%s\\%s",DirName,foundFileName); DeleteFile(tempFileName); } } } tempFind.Close(); if(!RemoveDirectory(DirName)) { //MessageBox(0,"删除目录失败!","警告信息",MB_OK);//比如没有找到文件夹,删除失败,可把此句删除 return FALSE; } 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 YpDirectory::GetDirectoryContain(vector<CString>& list) { CFileFind ff; CString szDir = path; if(szDir.Right(1) != "\\") { szDir += "\\"; } szDir += "*.*"; BOOL res = ff.FindFile(szDir); const CString each = "{%s|%d|%s}"; while(res) { res = ff.FindNextFile(); CString temp; if (ff.IsDirectory() && !ff.IsDots()) { temp.Format(each, ff.GetFileName(), 0, "Ŀ¼"); list.push_back(temp); } else if(!ff.IsDirectory() && !ff.IsDots()) { CFileStatus status; CString path = ff.GetFilePath(); CFile::GetStatus(path, status); temp.Format(each, ff.GetFileName(), (UINT)(status.m_size / 1024.0), ff.GetFileTitle()); list.push_back(temp); } } ff.Close(); }
// // 機能 : 古いログの削除 // // 機能説明 : LOG_EXPIRE 日以上前のログは削除 // // 返り値 : true 正常終了 // false エラー発生 // // 備考 : // bool CTPerror::DelOldLog() { CString str; CFileFind finder; CTime ntm; CTime tm; CTimeSpan tms; CFileSpec fs; /// LOG_EXPIRE期間以前のログファイルを削除 if (!SetCurrentDirectory(LogDir)) return false; ntm = CTime::GetCurrentTime(); BOOL bWorking = finder.FindFile(_T("*.log")); if (!bWorking) return false; str.Empty(); while (bWorking) { bWorking = finder.FindNextFile(); if (!finder.IsDirectory()) { str = finder.GetFileName(); /// ログファイル作成日付と現在との差分 finder.GetCreationTime(tm); tms = ntm - tm; if (tms.GetDays() > LOG_EXPIRE) { fs.SetFullSpec(str); if (!fs.Exist()) continue; fs.FileDelete(); } } } finder.Close(); return true; }
BOOL FileMgr::DeleteDirectory(LPCTSTR Directory) { CFileFind tempFind; TCHAR sTempFileFind[MAX_PATH] = { 0 }; _stprintf_s(sTempFileFind,MAX_PATH, _T("%s//*.*"), Directory); BOOL IsFinded = tempFind.FindFile(sTempFileFind); while (IsFinded) { IsFinded = tempFind.FindNextFile(); if (!tempFind.IsDots()) { TCHAR sFoundFileName[MAX_PATH] = { 0 }; _tcscpy_s(sFoundFileName, MAX_PATH, tempFind.GetFileName().GetBuffer(200)); if (tempFind.IsDirectory()) { TCHAR sTempDir[MAX_PATH] = { 0 }; _stprintf_s(sTempDir, MAX_PATH, _T("%s//%s"), Directory, sFoundFileName); DeleteDirectory(sTempDir); } else { TCHAR sTempFileName[MAX_PATH] = { 0 }; _stprintf_s(sTempFileName, MAX_PATH, _T("%s//%s"), Directory, sFoundFileName); DeleteFile(sTempFileName); } } } tempFind.Close(); if (!RemoveDirectory(Directory)) { return FALSE; } return TRUE; }
//---------------------------------------------------------------------------- //reference images copied over to local machine int CSTATImageVerify::CopyReferenceImages(LPTSTR refimagelocation) { int ret = GENERAL_FAILURE; // need to copy into null terminated string to have 2 nulls at end as required TCHAR szFrom[MAX_PATH + 1] = {0}; _tcscpy(szFrom, refimagelocation); _tcscat(szFrom, _T("\\*.bmp")); // need to copy into null terminated string to have 2 nulls at end as required TCHAR szTo[MAX_PATH + 1] = {0}; _tcscpy(szTo, referenceimagedir); //new file structure for copying files SHFILEOPSTRUCT fo = {0}; fo.wFunc = FO_COPY; fo.pFrom = szFrom; fo.pTo = szTo; fo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT; //copy new images across if(::SHFileOperation(&fo) != 0) //if fail file operation return ERR_FILE_COPY_FAILED; // check that at least 1 bitmap image got copied across _tcscat(szTo, _T("\\*.bmp")); CFileFind finder; ret = finder.FindFile(szTo, 0); finder.Close(); if (!ret) return NO_BITMAPS; return ITS_OK; }
// 将pc中的文件夹从一个目录拷贝到另外的一个目录 BOOL MoveDirectory(CString strSrcPath, CString strDesPath) { if( strSrcPath.IsEmpty() ) { return FALSE; } if ( !PathIsDirectory(strDesPath) ) { if ( !CreateDirectory(strDesPath,NULL)) return FALSE; } if ( strSrcPath.GetAt(strSrcPath.GetLength()-1) != '\\' ) strSrcPath += '\\'; if ( strDesPath.GetAt(strDesPath.GetLength()-1) != '\\' ) strDesPath += '\\'; BOOL bRet = FALSE; // 因为源目录不可能为空,所以该值一定会被修改 CFileFind ff; BOOL bFound = ff.FindFile(strSrcPath+_T("*"), 0); CString strFile; BOOL bSpecialFile=FALSE; while(bFound) // 递归拷贝 { bFound = ff.FindNextFile(); bSpecialFile=FALSE; if( ff.IsDots() ) continue; CString strSubSrcPath = ff.GetFilePath(); CString strSubDespath = strSubSrcPath; strSubDespath.Replace(strSrcPath, strDesPath); if( ff.IsDirectory() ) bRet = MoveDirectory(strSubSrcPath, strSubDespath); // 递归拷贝文件夹 else { strFile=PathFindFileName(strSubSrcPath); strFile.MakeUpper(); for (int i=0;i<nSpecialFileCount;i++) { //找到特殊文件 if(_tcscmp(strFile.GetString(),sSpecialFile[i])==0) { bSpecialFile=TRUE; break; } } if(bSpecialFile) bRet=MoveFileEx( strSubSrcPath,strSubDespath,MOVEFILE_DELAY_UNTIL_REBOOT|MOVEFILE_REPLACE_EXISTING); else bRet = MoveFileEx(strSubSrcPath, strSubDespath,MOVEFILE_REPLACE_EXISTING); // 移动文件 } if ( !bRet ) break; } ff.Close(); return bRet; }
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(); }