7z get total size of uncompress contents?
Asked Answered
G

3

6

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.

Gutter answered 5/10, 2010 at 16:53 Comment(1)
I don't quite get what you mean by the "filename interfering with the code counting the size of each file", but if you are going for a machine-readable format, you might be interested in the -slt command line option.Surely
R
8

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
Rodrigorodrigue answered 16/4, 2016 at 5:58 Comment(3)
Worth saying if you redirect the output of 7z.exe l path\*.zip to a text file then you get a very useful summation at the end of the text so you know what your total input and output file sizes are.Brainpan
Also worth saying that the 7z command is available via the p7zip apt package on Ubuntu and many similar Linux systems, and also produces the described output.Naumann
if there are many zip files, one might just need Totals, then 7z l '*ZIP'|tail -n 3 will print like Archives: 1671 Volumes: 1671 Total archives size: 637398326Ellora
H
1

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}'
Hydrothermal answered 12/4, 2011 at 18:31 Comment(0)
T
1

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
Transmutation answered 14/7, 2019 at 22:27 Comment(1)
For Powershell I had to tweak your script a bit: & 'C:\Program Files\7-Zip\7z.exe' l '.\*.7z' | select-string -pattern ".* files" | Foreach {$size=[long]"$(($_ -split '\s+',4)[2])";$total+=$size};"$([math]::Round($total/1024/1024/1024,2))" + " GB" as archive might have more than 1 file in itMarquess

© 2022 - 2024 — McMap. All rights reserved.