整理一下自己从网上找的资料,简单的说就是调用Windows系统命令行的打包指令:
Compress-Archive
PowerShell Commands Compress-Archive
这篇文章的重点在这:
Compress-Archive relies upon the Microsoft .NET Framework API System.IO.Compression.ZipArchive to compress files
How should C++ execute the PowerShell command?
结合上述,就可以写出如何用C++打包文件:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream file;
file.open("test.ps1");
string newArg = "-auto";
string powershell;
powershell = "Compress-Archive -Path F:/AVL -DestinationPath F:/AVL.zip";
file << powershell << endl;
file.close();
system("powershell -ExecutionPolicy Bypass -F test.ps1");
remove("test.ps1");
printf("\n task end!!\n");
}