Chinaunix首页 | 论坛 | 博客
  • 博客访问: 459052
  • 博文数量: 107
  • 博客积分: 6073
  • 博客等级: 准将
  • 技术积分: 790
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-14 15:34
文章分类

全部博文(107)

文章存档

2010年(1)

2009年(106)

分类: C/C++

2010-01-06 10:06:20

作者:wangxinus,
来源:
http://wangxinus.cublog.cn
说明:原创文章欢迎转载,交流请Email给作者


#include
#include
/*
  qCopyDirectory -- 拷贝目录
  fromDir : 源目录
  toDir   : 目标目录
  bCoverIfFileExists : ture:同名时覆盖  false:同名时返回false,终止拷贝
  返回: ture拷贝成功 false:拷贝未完成
*/
bool qCopyDirectory(const QDir& fromDir, const QDir& toDir, bool bCoverIfFileExists)
{
    QDir formDir_ = fromDir;
    QDir toDir_ = toDir;

    if(!toDir_.exists())
    {
        if(!toDir_.mkdir(toDir.absolutePath()))
            return false;
    }

    QFileInfoList fileInfoList = formDir_.entryInfoList();
    foreach(QFileInfo fileInfo, fileInfoList)
    {
        if(fileInfo.fileName() == "." || fileInfo.fileName() == "..")
            continue;

        //拷贝子目录
        if(fileInfo.isDir())
        {
            //递归调用拷贝
            if(!qCopyDirectory(fileInfo.filePath(), toDir_.filePath(fileInfo.fileName())))
                return false;
        }
        //拷贝子文件
        else
        {
            if(bCoverIfFileExists && toDir_.exists(fileInfo.fileName()))
            {
                toDir_.remove(fileInfo.fileName());
            }
            if(!QFile::copy(fileInfo.filePath(), toDir_.filePath(fileInfo.fileName())))
            {
                return false;
            }
        }
    }
    return true;
}
阅读(2223) | 评论(0) | 转发(0) |
0

上一篇:第一个Arm程序led(ASD1.2)

下一篇:没有了

给主人留下些什么吧!~~