【发布时间】:2012-07-19 01:20:15
【问题描述】:
我正在尝试压缩一些文件夹。它们有不同的路径,不会属于同一个目录。
我测试了我要给出的命令行参数,它可以工作,但我无法在 c# 中让它工作:
string destination = "some path\\name.7z";
string pathToZip = "path to zip\\7z.exe"; // or 7za.exe
ProcessStartInfo p = new ProcessStartInfo();
p.FileName = pathToZip;
p.Arguments = "a \"" + destination + "\" \"";
// room for the foreach - but even one directory doesn't work right now
p.Arguments += directoryPath + "\" \"";
p.Arguments += "\" -mx=9 -aoa";
Process x = Process.Start(p);
使用 7z.exe 我会眨眼;使用 7za.exe,我获得了典型的命令行 zip 序列,文件通过压缩,添加到存档,然后创建存档。
然后我转到它并右键单击、打开或双击...我知道它是一个无效的存档 (Can not open file "name.7z" as an archive)。尝试使用 7za 的命令行来提取 - 同样的东西。
编辑:我找到了解决方案:
我的问题是 -aoa 选项(我用于覆盖) - 删除它后,它起作用了。
【问题讨论】:
-
无论你用 p.Arguments 做什么都很糟糕,没有人能读懂它而不让眼睛流血!
-
同意。我在这里推荐
StringBuilder,因为您在for/foreach 循环中进行字符串连接。