Skip to content

Instantly share code, notes, and snippets.

@abom
Last active February 22, 2018 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abom/3a33561e7f305d33edbf422223423ec6 to your computer and use it in GitHub Desktop.
Save abom/3a33561e7f305d33edbf422223423ec6 to your computer and use it in GitHub Desktop.
Get uncompressed size of all zip files inside a directory
# encoding: utf-8
from __future__ import unicode_literals
import os
import zipfile
def is_zip_file(path):
return os.path.isfile(path) and zipfile.is_zipfile(path)
def list_zip_files(dir_path):
return filter(is_zip_file, os.listdir(dir_path))
def get_uncompressed_size(path):
if os.path.isdir(path):
return sum(map(get_uncompressed_size, list_zip_files(path)))
archive = zipfile.ZipFile(path)
return sum([info.file_size for info in archive.infolist()])
print get_uncompressed_size('.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment