void DeleteFolder(CString dir) { if(FileIsDirectory(dir)) { //SHFILEOPSTRUCT Op; //ZeroMemory(&Op, sizeof(Op)); //删除文件夹 //Op.hwnd = NULL; //Op.wFunc = FO_DELETE; //Op.pFrom = dir; //Op.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION; //SHFileOperation(&Op); CFindFile tempFind; CString tempFileFind; tempFileFind.Format(_T("%s\\*.*"),dir); BOOL IsFinded = tempFind.FindFile(tempFileFind); while (IsFinded) { IsFinded = tempFind.FindNextFile(); if(!tempFind.IsDots()) { if(tempFind.IsDirectory()) DeleteFolder(tempFind.GetFilePath()); else DeleteFile(tempFind.GetFilePath()); } } tempFind.Close(); RemoveDirectory(dir); } }
bool CClientApp::EnumAllFiles(string sFolder) { if ( sFolder.length() == 0 ) return false; bool bRet = false; CFindFile fFind; string sFindStr = sFolder + "\\*.*"; BOOL bFind = fFind.FindFile( sFindStr.c_str() ); while ( bFind ) { bRet = true; if ( fFind.IsDirectory() ) { if ( !fFind.IsDots() ) { if ( !EnumAllFiles( fFind.GetFilePath().GetBuffer(0) ) ) { bRet = false; break; } } } else { CMediaFile* pMediaFile = new CMediaFile(); if ( pMediaFile ) { if ( pMediaFile->InitFile( fFind.GetFilePath().GetBuffer(0), fFind.GetFileName().GetBuffer(0) ) ) { pMediaFile->m_sNodeName = "Kevin_Test_Node_Name"; m_MediaFileMgr.Insert( pMediaFile->m_sFileHash, pMediaFile ); // 查找到立即发布 PublishFiles(); } else { delete pMediaFile; CKLog::WriteLog( LOG_TYPE_DEBUG, "%s InitFile Failed.", fFind.GetFilePath() ); WriteLog( LOG_TYPE_DEBUG, "%s InitFile Failed.", fFind.GetFilePath() ); } } } bFind = fFind.FindNextFile(); } fFind.Close(); return bRet; }
//============================================================================= // 函数名称: 移动覆盖一个指定的目录 // 作者说明: mushuai // 修改时间: 2013-03-14 //============================================================================= int ConvertPath(LPCTSTR srcpath,LPCTSTR targpath) { int iresult = 1; CFindFile finder; if(finder.FindFile(srcpath)) { CString fileName,filePath; do { fileName=finder.GetFileName(); filePath = finder.GetFilePath(); //. .. if (finder.IsDots()) { continue; } //dir else if (finder.IsDirectory()) { CString tTargPath = targpath; tTargPath +=_T("\\")+fileName; ConvertPath(filePath+_T("\\*"),tTargPath); RemoveDirectory(filePath); } else//file { CString newFilePath = targpath; newFilePath +=_T("\\")+fileName; if (!PathFileExists(targpath)) { if(ERROR_SUCCESS != SHCreateDirectoryEx(0,targpath,0)) { return 0; } } BOOL res=MoveFileEx(filePath,newFilePath,MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING); if (!res) { SetFileAttributes(newFilePath,FILE_ATTRIBUTE_NORMAL); if (!DeleteFile(newFilePath)) { MoveFileEx(filePath,newFilePath,MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING); } } } }while (finder.FindNextFile()); } finder.Close(); return iresult; }