mthq
mthq

Reputation: 17

Powershell script to list Zip files in a Directory with their Size

I have came across a way to list Zip content in a Directory - I would like to include the file size information.

[Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem')
foreach($sourceFile in (Get-ChildItem -filter '*.zip'))
{
    [IO.Compression.ZipFile]::OpenRead($sourceFile.FullName).Entries.FullName |
            %{ "$sourcefile`:$_" }
}

Could someone help me to add size information - current display format is:

zipName:zipContentName

I would like to keep formatting as:

zipName:zipContentName:zipContentSize

Upvotes: 1

Views: 2991

Answers (1)

Peter Hahndorf
Peter Hahndorf

Reputation: 11222

Rather than looping through the FullNames, loop through the entries themselves:

[Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem')
foreach($sourceFile in (Get-ChildItem -filter '*.zip'))
{
    [IO.Compression.ZipFile]::OpenRead($sourceFile.FullName).Entries |
            %{ "$sourcefile`:$($_.FullName):$($_.Length)";  }
}

Upvotes: 3

Related Questions