#!/usr/bin/env python # used to uncompress the summary all_xx.zip files downloaded from the # census bureau's web site. # # this program uncompresses the zip files (and zips within zip files) # and places the uncompressed files in a single directory import zipfile, os def unzip(path): __zip = zipfile.ZipFile(path) for __name in __zip.namelist(): __basename="./downloads/"+os.path.basename(__name) print __basename if __name.endswith('.zip'): file(__basename, 'wb').write(__zip.read(__name)) unzip(__basename) os.remove(__basename) elif not __name.endswith('/'): file(__basename, 'wb').write(__zip.read(__name)) for __root, __dirs, __files in os.walk("./downloads"): for __file in __files: if __file.endswith(".zip"): unzip(os.path.join(__root, __file))