2012-05-20 9 views
10

Windowsでファイルを解凍すると、私は時折、オリジナルOSにWindows用は長すぎる(大丈夫パス長すぎるパスでZIPファイルを解凍処理するためにどのように/

  1. に問題があるでしょう複製ファイルを作成しました)。これらの問題のうちの1つでzipファイルを読み込むたびに起因DotNetZipを使用した場合、鈍感

に「複製」されている

  • は、ZipFile.Read(path)コールはがらくたます。つまり、私はそれをフィルタリングしようとすることはできません。

    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.Dictionary 2.Insert(TKey key, TValue value, Boolean add)
    at System.Collections.Generic.Dictionary
    2.Add(処理鍵キー、TValue値)で
    Ionic.Zip.ZipFile.ReadCentralDirectory(ZIPファイルZF)で

    ATで
    Ionic.Zip.ZipFile.ReadIntoInstance(ZIPファイル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 }); 
          } 
         } 
        } 
    } 
    
  • +0

    ファイルは.zipまたは.gzですか? – SimpleVar

    +0

    .zip(特にgithubファイルからダウンロード) – gameweld

    +0

    エラーを表示できますか?ファイル内のパス名ですか?ターゲットファイルの場所が長すぎますか? – yamen

    答えて

    3

    ZipInputStreamで読み込みます。

    ZipFileクラスは、ファイル名をインデックスとして使用してコレクションを保持します。ファイル名が重複すると、そのモデルが破損します。

    ただし、ZipInputStreamを使用してzipファイルを読み取ることができます。その場合、コレクションまたはインデックスはありません。

    8

    PathTooLongExceptionの問題については、DotNetZipを使用できないことがわかりました。代わりに、私がしたのはcommand-line version of 7-zipです。それは不思議に作用します。

    public static void Extract(string zipPath, string extractPath) 
    { 
        try 
        { 
         ProcessStartInfo processStartInfo = new ProcessStartInfo 
         { 
          WindowStyle = ProcessWindowStyle.Hidden, 
          FileName = Path.GetFullPath(@"7za.exe"), 
          Arguments = "x \"" + zipPath + "\" -o\"" + extractPath + "\"" 
         }; 
         Process process = Process.Start(processStartInfo); 
         process.WaitForExit(); 
         if (process.ExitCode != 0) 
         { 
          Console.WriteLine("Error extracting {0}.", extractPath); 
         } 
        } 
        catch (Exception e) 
        { 
         Console.WriteLine("Error extracting {0}: {1}", extractPath, e.Message); 
         throw; 
        } 
    } 
    
    +2

    これは実際に私が見つけた最も簡単な解決策です。このコメントの時点では、7za.exeが「7-zip extra:....」という7-zipのダウンロードに含まれていることを知っておくと役に立ちます。 (http://www.7-zip.org/download.html) –

    +0

    'Arguments'行が間違っています。 **引数** = "x" "+ zipPath +" \ "-o \" "+ extractPath +" \ "" '(** o **スイッチと' extractPath'の間にスペースはありません) – sigil

    +0

    ありがとう@ sigil、[this(http://superuser.com/questions/95902/7-zip-and-unzipping-from-command-line)によると、あなたは正しいです、私は私の答えを更新しました。 –

    関連する問題