仅显示zip存档中的文件夹

时间:2015-08-05 07:27:48

标签: c# zip directory names

如何仅显示文件夹'来自zip存档的名称而不使用C#解压缩它?

当文件夹名为abc.csv?

时,如何处理案例?

1 个答案:

答案 0 :(得分:0)

以下代码使用了稍微修改过的lib DotNetZip中的示例。这是他们的示例部分,所以我没有尝试编译这个fyi。

using (ZipFile zip = ZipFile.Read(ExistingZipFile))
{
foreach (ZipEntry e in zip)
{
  if (header)
  {
    System.Console.WriteLine("Zipfile: {0}", zip.Name);
    if ((zip.Comment != null) && (zip.Comment != "")) 
      System.Console.WriteLine("Comment: {0}", zip.Comment);
    System.Console.WriteLine("\n{1,-22} {2,8}  {3,5}   {4,8}  {5,3} {0}",
                             "Filename", "Modified", "Size", "Ratio", "Packed", "pw?");
    System.Console.WriteLine(new System.String('-', 72));
    header = false;
  }
  System.Console.WriteLine("{1,-22} {2,8} {3,5:F0}%   {4,8}  {5,3} {0}",
                           e.FileName,
                           e.LastModified.ToString("yyyy-MM-dd HH:mm:ss"),
                           e.UncompressedSize,
                           e.CompressionRatio,
                           e.CompressedSize,
                           (e.UsesEncryption) ? "Y" : "N");
  if(e.IsDirectory)
  {
   //Add to a list or whatever it is you wanna do
  }

 }
}