File: unzip.py

package info (click to toggle)
opendict 0.6.5-3
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,056 kB
  • ctags: 884
  • sloc: python: 6,382; makefile: 135; sh: 71; xml: 41
file content (20 lines) | stat: -rw-r--r-- 544 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env python
# learn how to use zipfile module

import sys, zipfile, os, os.path

def unzip_file_into_dir(file, dir):
    os.mkdir(dir, 0777)
    zfobj = zipfile.ZipFile(file)
    for name in zfobj.namelist():
        if name.endswith('/'):
            os.mkdir(os.path.join(dir, name))
        else:
            outfile = open(os.path.join(dir, name), 'wb')
            outfile.write(zfobj.read(name))
            outfile.close()

def main():
    unzip_file_into_dir(open(sys.argv[1]), sys.argv[2])

if __name__ == '__main__': main()