|
Revision 1, 0.5 kB
(checked in by mjoc, 2 years ago)
|
Initial import.
|
| Line | |
|---|
| 1 |
#!/usr/bin/env python |
|---|
| 2 |
# learn how to use zipfile module |
|---|
| 3 |
|
|---|
| 4 |
import sys, zipfile, os, os.path |
|---|
| 5 |
|
|---|
| 6 |
def unzip_file_into_dir(file, dir): |
|---|
| 7 |
os.mkdir(dir, 0777) |
|---|
| 8 |
zfobj = zipfile.ZipFile(file) |
|---|
| 9 |
for name in zfobj.namelist(): |
|---|
| 10 |
if name.endswith('/'): |
|---|
| 11 |
os.mkdir(os.path.join(dir, name)) |
|---|
| 12 |
else: |
|---|
| 13 |
outfile = open(os.path.join(dir, name), 'wb') |
|---|
| 14 |
outfile.write(zfobj.read(name)) |
|---|
| 15 |
outfile.close() |
|---|
| 16 |
|
|---|
| 17 |
def main(): |
|---|
| 18 |
unzip_file_into_dir(open(sys.argv[1]), sys.argv[2]) |
|---|
| 19 |
|
|---|
| 20 |
if __name__ == '__main__': main() |
|---|