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