【问题标题】:Why does IO.Compression.ZipFile count of Entries not match 7zip GUI?为什么 IO.Compression.ZipFile 条目数与 7zip GUI 不匹配?
【发布时间】:2018-12-07 02:10:17
【问题描述】:

我正在尝试通过计算像 this 答案这样的压缩条目的数量来验证 PowerShell 中 ZIP 存档的内容。

但是,7Zip GUI、gci、Entries.Count 和 7Zip CLI 的结果不一致,例如:

(Get-ChildItem -path $sourceFolder -Recurse | where { ! $_.PSIsContainer }).Count

= 77779 个文件

[IO.Compression.ZipFile]::OpenRead($zipFile).Entries.Count

= 77838 个条目

&'c:\Program Files\7-Zip\7z.exe' l $zipFile

= 77779 个文件,59 个文件夹(即 77838 个对象)

但是 59 个文件夹计数是错误的 - 7Zip GUI 显示 77779 个文件和 35726 个文件夹。

有没有办法从 .Entries 中排除文件夹?否则我可以解析出来自 7z.exe l 命令的结果,如this,但更喜欢本机方法

【问题讨论】:

  • 当您将每个文件解压缩到新目录时,您会观察到什么?将 2 与无法比较之类的进行比较...

标签: powershell zip system.io.compression


【解决方案1】:

您可以进行自定义计数...如果条目仅指定一个文件夹,请跳过它:

($zip.entries.where({!$_.FullName.EndsWith('/')})).count

【讨论】:

  • 谢谢 - 我不知道目录条目以“/”结尾,但这完全有道理
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多