2016-04-21 164 views

回答

0

我想类似的东西,并使用Google(白白)提供代码,所以这是我必须:

static bool cpDir(const QString &srcPath, const QString &dstPath) 
    { 
     rmDir(dstPath); 
     QDir parentDstDir(QFileInfo(dstPath).path()); 
     if (!parentDstDir.mkdir(QFileInfo(dstPath).fileName())) 
      return false; 

     QDir srcDir(srcPath); 
     foreach(const QFileInfo &info, srcDir.entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot)) { 
      QString srcItemPath = srcPath + "/" + info.fileName(); 
      QString dstItemPath = dstPath + "/" + info.fileName(); 
      if (info.isDir()) { 
       if (!cpDir(srcItemPath, dstItemPath)) { 
        return false; 
       } 
      } else if (info.isFile()) { 
       if (!QFile::copy(srcItemPath, dstItemPath)) { 
        return false; 
       } 
      } else { 
       qDebug() << "Unhandled item" << info.filePath() << "in cpDir"; 
      } 
     } 
     return true; 
    } 
相关问题