我已经使用下面的代码片段来制作 zip 文件夹Ionic.zip
:
string lastFolder = packageSpec.FolderPath.Split('\\')[packageSpec.FolderPath.Split('\\').Length - 1];
string zipRoot = packageSpec.FolderPath + "\\Zip" + lastFolder;
string fileName = zipRoot + "\\" + lastFolder + ".zip";
Logging.Log(LoggingMode.Prompt, "Spliting to zip part...");
if (!Directory.Exists(zipRoot))
Directory.CreateDirectory(zipRoot);
ZipFile zip = new ZipFile();
zip.AddDirectory(packageSpec.FolderPath, zipRoot);
zip.MaxOutputSegmentSize = 200 * 1024 * 1024; // 200 MB segments
zip.Save(fileName);
它可以很好地创建多个 zip 部分,但会生成意外的嵌套文件夹,如下所示:如果变量是:
FolderPath = C:\MSR\Temp\Export_1
zipRoot = C:\MSR\Temp\Export_1\ZipExport_1
fileName= C:\MSR\Temp\Export_1\ZipExport_1\Export_1.zip
我的来源如下图所示:
1-是我的源文件夹,它的工作人员要压缩
2-是 zip 文件夹将包含 1zip.AddDirectory(packageSpec.FolderPath, zipRoot);
但我最终得到:
所以这些文件夹MSR->Temp->Export_1->ZipExport_1->ZipExport1
是额外的,这意味着 Export_1.zip 应该有直接的源文件夹而不是嵌套的额外文件夹。
有谁知道我可以如何更改该代码段来做到这一点?
提前致谢。