只显示zip归档文件中的文件夹

本文关键字:文件夹 归档文件 显示 zip | 更新日期: 2023-09-27 18:06:21

如何从zip存档中只显示文件夹的名称而不使用c#解压缩它?

如何处理文件夹名为abc.csv的情况?

只显示zip归档文件中的文件夹

下面的代码使用略微修改过的lib DotNetZip中的示例。这是来自他们的示例部分,所以我没有尝试编译它。

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
  }
 }
}