用QFile,复制多个exe类型文件到指定路径
时间: 2024-03-16 16:47:55 浏览: 20
可以使用QFile::copy方法将多个exe类型文件复制到指定路径。具体实现可以参考下面的代码示例:
```cpp
#include <QCoreApplication>
#include <QFile>
#include <QDir>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
// 源文件路径列表
QStringList fileList;
fileList << "file1.exe" << "file2.exe" << "file3.exe";
// 目标文件夹路径
QString destDirPath = "D:/target/";
// 创建目标文件夹
QDir destDir(destDirPath);
if (!destDir.exists()) {
destDir.mkpath(".");
}
// 复制文件
foreach (QString filePath, fileList) {
QString srcFilePath = "D:/source/" + filePath;
QString destFilePath = destDirPath + filePath;
if (QFile::copy(srcFilePath, destFilePath)) {
qDebug() << "复制成功:" << destFilePath;
} else {
qDebug() << "复制失败:" << destFilePath;
}
}
return a.exec();
}
```
注意,上述代码中需要根据实际情况修改源文件路径列表和目标文件夹路径。
相关推荐
![cpp](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)