Last active
February 22, 2018 17:22
-
-
Save abom/3a33561e7f305d33edbf422223423ec6 to your computer and use it in GitHub Desktop.
Get uncompressed size of all zip files inside a directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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