Skip to content

Instantly share code, notes, and snippets.

@tmcw tmcw/gist:90594
Created Apr 6, 2009

Embed
What would you like to do?
from optparse import OptionParser
import subprocess, os, re
'''
Runzip: recursively unzip
'''
parser = OptionParser()
parser.add_option('-d', '--dir',
action='store',
type='string',
help='base directory to start on',
default='./')
parser.add_option('-r', '--remove',
action='store_true',
help='delete zip files after successfully unzipping',
default=False)
def runzip(root, file, options):
subprocess.call('unzip %s -d %s' % (os.path.join(root, file), root), shell=True)
if options.remove:
print "deleting %s..." % file
subprocess.call('rm %s' % (os.path.join(root, file)), shell=True)
def main(options, args):
for root, dirs, files in os.walk(options.dir):
for file in files:
if re.search('\.zip', file): # is zip
runzip(root, file, options)
if __name__ == '__main__':
(options, args) = parser.parse_args()
main(options, args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.