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.
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
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
精彩评论