-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzipls.ps1
38 lines (32 loc) · 898 Bytes
/
zipls.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
param(
[Parameter(Mandatory)]
[Alias("Path")]
[string]
$ZIPFile,
[Parameter(Mandatory=$false)]
[string]
$OnlyMatching
)
Add-Type -AssemblyName "System.IO.Compression.Filesystem"
$ZIPFile = Get-Item $ZIPFile
$zip = [io.compression.zipfile]::OpenRead($ZIPFile)
for ($i = 0; $i -lt $zip.Entries.Count; $i++) {
$entry = $zip.Entries[$i]
if ($OnlyMatching.Length -gt 1) {
if ($entry.FullName -notmatch $OnlyMatching) {
continue
}
}
if ($entry.Length -gt 0) {
$compression_ratio = [System.Math]::Round(($entry.CompressedLength/$entry.Length)*100)
} else {
$compression_ratio = -1
}
#$size = [System.Math]::Round($entry.Length/1024)
$size = [System.Math]::Ceiling($entry.Length/4096)*4
if ($compression_ratio -lt 0) {
Write-Output $entry.FullName
} else {
Write-Output "$($entry.FullName) ($size kB, $compression_ratio %)"
}
}