使用 Dot Net Zip 列出目录中的所有文件?

发布于 2024-09-12 13:05:31 字数 266 浏览 4 评论 0原文

无论如何,Dot Net Zip 中是否可以用来列出特定目录中的所有文件名?例如,我可以指定 Directory1 并获取 File3 和 File4 等

ZipFile
-------

File1
File2
Directory1
     File3
     File4
Directory2
     File5
     File6

ZipFile 对象只有条目、已排序条目和条目文件名...

有人吗?Cheeso? :)

Is there anyway in Dot Net Zip that I can use to list all the names of files in a specific directory? For example, i can specify Directory1 and get File3 and File4 etc

ZipFile
-------

File1
File2
Directory1
     File3
     File4
Directory2
     File5
     File6

ZipFile object has only Entries, Entries Sorted, and Entries File Names...

Anyone?, Cheeso? :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别在捏我脸啦 2024-09-19 13:05:31

不,是的。没有 EntriesInDirectory 集合。然而,通过字符串比较来选择“属于”特定目录的条目是一个简单的问题。

在 LINQ 中,它看起来像这样:

var selection = from e in zip.Entries 
    where e.FileName.StartsWith(directoryName)
    select e;

在 for 循环中,它看起来像这样:

var list = new List<ZipEntry>();
foreach (var e in zip.Entries) {
  if (e.FileName.StartsWith(directoryName)) {
    list.Add(e);
  }
}

编辑

您可能必须进行区分大小写的转换。在 Windows 上,文件名中的大小写没有意义。

进一步说明:zip 格式不会将 zip 文件中的目录条目视为容器。目录项和文件项之间不存在容器关系。判断文件条目是否“属于”特定目录的唯一方法是检查文件条目的全名。如果条目的名称以相关目录的名称开头,则该条目位于该目录“中”。

No, and yes. There is no EntriesInDirectory collection. However, it's a simple matter of string comparison to select entries that "belong" in a particular directory.

In LINQ it looks like this:

var selection = from e in zip.Entries 
    where e.FileName.StartsWith(directoryName)
    select e;

In a for loop, it looks like this:

var list = new List<ZipEntry>();
foreach (var e in zip.Entries) {
  if (e.FileName.StartsWith(directoryName)) {
    list.Add(e);
  }
}

EDIT

You may have to do conversions for case sensitivity. On Windows, case is not meaningful in file names.

Further Explanation: the zip format doesn't treat a directory entry in the zip file as a container. There is no container relationship between directory entries and file entries. The only way to tell if a file entry "belongs in" a particular directory is to examine the full name of the file entry. If the name of the entry starts with the name of the directory in question, then the entry is "in" the directory.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文