user34537
user34537

Reputation:

7z get total size of uncompress contents?

How might i get the size of the contents of a zip/rar/7z file after full extraction? Under both windows and linux. I thought about using 7z l filename command but i dont like the idea of the filename interfering with the code counting the size of each file.

Upvotes: 6

Views: 12147

Answers (3)

samson7point1
samson7point1

Reputation: 11

Using Powershell:

'C:\Program Files\7-Zip\7z.exe' l '.\folder-with-zips\*.zip' | select-string -pattern "1 files" | Foreach {$size=[long]"$(($_ -split '\s+',4)[2])";$total+=$size};"$([math]::Round($total/1024/1024/1024,2))" + " GB"

Or if you want to watch it total things in real-time.

'C:\Program Files\7-Zip\7z.exe' l '.\folder-with-zips\*.zip' | select-string -pattern "1 files" | Foreach {$size=[long]"$(($_ -split '\s+',4)[2])";$total+=$size;"$([math]::Round($total/1024/1024/1024,2))" + " GB"}

If you run it multiple times, don't forget to reset your "total" variable in between runs, otherwise it'll just keep adding up

Remove-variable total

Upvotes: 1

bryc
bryc

Reputation: 14947

The command line version of 7zip, 7z.exe, can print a list of files and their sizes, both compressed and uncompressed. This is done using the l flag.

Use this command:

7z.exe l path\folder.zip

You can also include wildcard which gives the overall total for all archives in a folder:

7z.exe l path\*.zip

Upvotes: 8

remikz
remikz

Reputation: 436

This doesn't solve your filename problem, but may be good enough for others and myself (in cygwin):

/cygdrive/c/Program\ Files/7-Zip/7z.exe l filename.zip | grep -e "files,.*folders" | awk '{printf $1}'

Upvotes: 1

Related Questions