【发布时间】:2015-08-05 07:27:47
【问题描述】:
如何在不使用 C# 解压的情况下仅显示 zip 存档中的文件夹名称?
文件夹名为abc.csv的情况如何处理?
【问题讨论】:
-
Stack Overflow 不是代码编写服务:请展示您到目前为止所做的尝试。 (另外,为什么名为
abc.csv的文件夹需要特殊处理?) -
作为程序员,我必须处理所有可能的情况。
如何在不使用 C# 解压的情况下仅显示 zip 存档中的文件夹名称?
文件夹名为abc.csv的情况如何处理?
【问题讨论】:
abc.csv 的文件夹需要特殊处理?)
以下代码使用来自库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
}
}
}
【讨论】: