[QT学习]拷贝文件

sourceDir源绝对路径,toDir目标绝对路径

 1 //拷贝文件:
 2 bool FileOperation::copyFileToPath(QString sourceDir ,QString toDir, bool coverFileIfExist)
 3 {
 4     toDir.replace("\\","/");
 5     if (sourceDir == toDir){
 6         return true;
 7     }
 8     if (!QFile::exists(sourceDir)){
 9         return false;
10     }
11     QFileInfo fi(toDir);
12     QString dirPath=fi.absolutePath();//取路径
13     QDir *createfile = new QDir;
14     bool exist=createfile->exists(dirPath);
15     if(!exist)
16     {
17         createfile->mkdir(dirPath);
18     }
19     exist = createfile->exists(toDir);
20     if (exist){
21         if(coverFileIfExist){
22             createfile->remove(toDir);
23         }
24     }//end if
25 
26     if(!QFile::copy(sourceDir, toDir))
27     {
28         return false;
29     }
30     return true;
31 }

 

posted @ 2016-04-23 10:38  赵天  阅读(2585)  评论(1编辑  收藏  举报