一、功能
递归拷贝文件到指定文件夹下,如果目标文件夹不存在,则创建
二、代码
bool qfileCopyFilePath::copyDir(const QDir& src,const QDir& dest)
{
QDir dirSrc(src);
QDir dirDest(dest);
if(!dirDest.exists()){
if(!dirDest.mkpath(dirDest.absolutePath()))
return false;
}
QFileInfoList fileInfoList = dirSrc.entryInfoList();
foreach(QFileInfo fileInfo, fileInfoList){
if(fileInfo.fileName() == "." || fileInfo.fileName() == "..")
continue;
if(fileInfo.isDir()){ //当为目录时,递归的进行copy
if(!copyDir(fileInfo.filePath(), dirDest.filePath(fileInfo.fileName())))
return false;
}
else{ // 进行文件copy
if(!QFile::copy(fileInfo.filePath(),dirDest.filePath(fileInfo.fileName()))){
return false;
}
}
}
return true;
}