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.
7z get total size of uncompress contents?
Asked Answered
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
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: 637398326
–
Ellora 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}'
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
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 it –
Marquess © 2022 - 2024 — McMap. All rights reserved.
-slt
command line option. – Surely