當在Windows中解壓縮文件,我會偶爾有路徑的問題如何處理與過長的路徑解壓的ZipFile /複製
- 是爲Windows在原有OS太長(但還好的是創建該文件)。
- 被「複製」,由於不區分大小寫
使用DotNetZip,該ZipFile.Read(path)
呼叫廢話了,只要用閱讀這些問題的一個zip文件。這意味着我甚至無法嘗試過濾出來。
using (ZipFile zip = ZipFile.Read(path))
{
...
}
什麼是處理讀取這些文件進行排序的最佳方式?
更新:從這裏
例ZIP: https://github.com/MonoReports/MonoReports/zipball/master
重複: https://github.com/MonoReports/MonoReports/tree/master/src/MonoReports.Model/DataSourceType.cs https://github.com/MonoReports/MonoReports/tree/master/src/MonoReports.Model/ DatasourceType.cs
這裏是例外的更多詳細信息:
Ionic.Zip.ZipException:無法讀取,作爲一個ZipFile的
---> System.ArgumentException:一個>具有相同的鍵項已被添加。
在System.ThrowHelper.ThrowArgumentException(ExceptionResource資源)
在System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add)
2.添加(TKEY的鍵,TValue值)
at System.Collections.Generic.Dictionary
在Ionic.Zip.ZipFile.ReadCentralDirectory(ZipFile的ZF)
在Ionic.Zip.ZipFile.ReadIntoInstance(ZipFile的ZF)
分辨率:
基於@ Cheeso的建議,我可以從流中讀取的一切,那些避免重複,路徑問題:
//using (ZipFile zip = ZipFile.Read(path))
using (ZipInputStream stream = new ZipInputStream(path))
{
ZipEntry e;
while((e = stream.GetNextEntry()) != null)
//foreach(ZipEntry e in zip)
{
if (e.FileName.ToLower().EndsWith(".cs") ||
e.FileName.ToLower().EndsWith(".xaml"))
{
//var ms = new MemoryStream();
//e.Extract(ms);
var sr = new StreamReader(stream);
{
//ms.Position = 0;
CodeFiles.Add(new CodeFile() { Content = sr.ReadToEnd(), FileName = e.FileName });
}
}
}
}
是文件.zip還是.gz? – SimpleVar
.zip文件(特別是從GitHub的壓縮文件下載) – gameweld
可以告訴你這個錯誤嗎?它是文件內的路徑名嗎?目標文件位置是否太長? – yamen