![](/img/trans.png)
[英].7z archive from my website is corrupted: “Can not open file as an archive.”
[英]c# create 7z archive, then Can not open file “name.7z” as an archive
我正在嘗試壓縮一些文件夾。 它們具有不同的路徑,將不屬於同一目錄。
我測試了我要給出的命令行參數,它可以工作,但是我不能從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選項(用於覆蓋)-刪除它后,它起作用了。
該代碼對我有用,在目錄中包含文件:
string destination = @"c:\my test.7z";
string pathToZip = @"C:\Program Files\7-Zip\7z.exe";
string directoryPath = @"c:\my test";
ProcessStartInfo p = new ProcessStartInfo();
p.FileName = pathToZip;
p.Arguments = string.Format("a -mx=9 \"{0}\" \"{1}\"", destination, directoryPath);
Process x = Process.Start(p);
7za.exe
是命令行程序,在這種情況下應使用它。
為什么要在命令行中添加""
? 那可能是造成您的問題。
此外,請確保你把你的"
身邊事,不要墊他們兩個在年底,這只是導致問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.