I know that you can get the size in bytes of a file in a ZIP file using the .file_size method But is there any what I can get the size of a folder instead?
Ex:
JavaScript
x
10
10
1
import zipfile, os
2
3
os.chdir('C:\')
4
zp= zipfile.ZipFile('example.zip')
5
6
spamInfo = zp.getinfo('spam.txt') #Here, Instead of a file I'd like to put a folder
7
spamInfo.file_size
8
9
zp.close()
10
Advertisement
Answer
JavaScript
1
7
1
import zipfile
2
3
zp = zipfile.ZipFile("example.zip")
4
5
size = sum([zinfo.file_size for zinfo in zp.filelist])
6
zip_kb = float(size) / 1000 # kB
7