Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created April 6, 2009 01:13
Show Gist options
  • Save tmcw/90594 to your computer and use it in GitHub Desktop.
Save tmcw/90594 to your computer and use it in GitHub Desktop.
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