Skip to content

Instantly share code, notes, and snippets.

@sergeytunnik
Created March 8, 2011 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergeytunnik/860331 to your computer and use it in GitHub Desktop.
Save sergeytunnik/860331 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import os
import sys
import zipfile
filename = 'list.txt'
archname = 'desktop.zip'
outdir = os.path.curdir
inputset = set()
if len(sys.argv) != 3:
print "Usage: zip.py /path/to/file.zip /output/dirname/"
sys.exit()
archname = sys.argv[1]
outdir = sys.argv[2]
for line in open(filename):
inputset.add(line.strip('\r\n'))
if zipfile.is_zipfile(archname):
arch = zipfile.ZipFile(archname, 'r')
else:
print '%s not a zip file' % archname
sys.exit()
if not os.path.exists(outdir):
print "Cant find output dir: %s" % outdir
sys.exit()
for info in arch.infolist():
if info.filename in inputset:
arch.extract(info, outdir)
print 'ok - %s' % os.path.join(outdir, info.filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment