bool FileCopy(QString sourcefile, QString toFile, bool IscoverFile)
{
toFile.replace("\", “/”);
if (sourcefile== toFile)
{
return true;
}
if (!QFile::exists(sourceDir))
{
return false;
}
QDir *createfile = new QDir;
bool exist = createfile->exists(toFile);
if (exist)
{
if (IscoverFile)
{
createfile->remove(toFile);
}
}//end if
if (!QFile::copy(sourcefile, toFile))
{
return false;
}
return true;
}
QString sourcefile, 源文件
QString toFile, 需要复制到的文件路径
bool IscoverFile 是否覆盖
不要与QDir的mkPath()混用,mkpath会直接创建路径信息(将文件信息以文件夹创建)
除了这个copy函数还可以用数据流的方式来进行复制拷贝,ifstrem 用起来也很方便