码迷,mamicode.com
首页 > 其他好文 > 详细

[QT学习]拷贝文件

时间:2016-04-23 11:51:27      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:

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 }

 

[QT学习]拷贝文件

标签:

原文地址:http://www.cnblogs.com/zhaotian/p/5424100.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!