資源描述:
《Qt拷貝文件、文件夾.doc》由會員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、//拷貝文件:boolMyTest007::copyFileToPath(QStringsourceDir,QStringtoDir,boolcoverFileIfExist){toDir.replace("\","/");if(sourceDir==toDir){returntrue;}if(!QFile::exists(sourceDir)){returnfalse;}QDir*createfile=newQDir;boolexist=createfile->exists(toDir);if(exist){if(coverFile
2、IfExist){createfile->remove(toDir);}}//endifif(!QFile::copy(sourceDir,toDir)){returnfalse;}returntrue;}//拷貝文件夾:boolMyTest007::copyDirectoryFiles(constQString&fromDir,constQString&toDir,boolcoverFileIfExist){QDirsourceDir(fromDir);QDirtargetDir(toDir);if(!targetDir.exists
3、()){/**<如果目標(biāo)目錄不存在,則進(jìn)行創(chuàng)建*/if(!targetDir.mkdir(targetDir.absolutePath()))returnfalse;}QFileInfoListfileInfoList=sourceDir.entryInfoList();foreach(QFileInfofileInfo,fileInfoList){if(fileInfo.fileName()=="."
4、
5、fileInfo.fileName()=="..")continue;if(fileInfo.isDir()){/**<當(dāng)為目錄時,
6、遞歸的進(jìn)行copy*/if(!copyDirectoryFiles(fileInfo.filePath(),targetDir.filePath(fileInfo.fileName()),coverFileIfExist))returnfalse;}else{/**<當(dāng)允許覆蓋操作時,將舊文件進(jìn)行刪除操作*/if(coverFileIfExist&&targetDir.exists(fileInfo.fileName())){targetDir.remove(fileInfo.fileName());}///進(jìn)行文件copyif(!QF
7、ile::copy(fileInfo.filePath(),targetDir.filePath(fileInfo.fileName()))){returnfalse;}}}returntrue;}