powershellzipsystem.io.compression

Why does IO.Compression.ZipFile count of Entries not match 7zip GUI?


I'm trying to verify the contents of a ZIP archive in PowerShell by counting the number of zipped entries like this answer.

However, the results are inconsistent between 7Zip GUI, gci, Entries.Count and 7Zip CLI, for example:

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

= 77779 files

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

= 77838 entries

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

= 77779 files, 59 folders (i.e. 77838 objects)

However the 59 folder count is wrong - the 7Zip GUI shows 77779 files and 35726 folders.

Is there a way to exclude folders from .Entries? Otherwise I could parse out the results from 7z.exe l command like this, but would prefer the native approach


Solution

  • You could do a custom count... If the entry only specifies a folder, skip it:

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