Advertisement
Ubidibity

AnalyzeZip.ps1

Jan 24th, 2025 (edited)
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. param (
  2.     [string]$zipPath
  3. )
  4.  
  5. # Used in dayz-bak.ps1 after zip generation but could be used other places as well.
  6.  
  7. # call like .\AnalyzeZip.ps1 $destZip to execute remotely
  8.  
  9. Add-Type -Assembly System.IO.Compression.FileSystem
  10.  
  11. # testing $zipPath="e:\dayz_backups\2501240336-dayz-server-bak.zip"
  12.  
  13. $zip = [IO.Compression.ZipFile]::OpenRead($zipPath)
  14. $fileCount = $zip.Entries.Count
  15. $totalSize = 0
  16.  
  17. foreach ($entry in $zip.Entries) {
  18.     $totalSize += $entry.Length
  19. }
  20.  
  21. $zip.Dispose()
  22.  
  23. # Convert size to a human-readable format
  24. function Get-HumanReadableSize {
  25.     param ([long]$bytes)
  26.     $suffix = @("B", "KB", "MB", "GB", "TB")
  27.     $i = 0
  28.     while ($bytes -ge 1kb -and $i -lt $suffix.Length - 1) {
  29.         $bytes = $bytes / 1kb
  30.         $i++
  31.     }
  32.     return "{0:N2} {1}" -f $bytes, $suffix[$i]
  33. }
  34.  
  35. "Number of files: $fileCount"
  36. "Total size: $(Get-HumanReadableSize -bytes $totalSize)"
  37.  
Tags: #DayZ
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement