Created
August 18, 2014 06:47
-
-
Save brain-zhang/66fcc37192c0c68d4fc4 to your computer and use it in GitHub Desktop.
compress each file in a folder to zip
This file contains hidden or 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
| #!/bin/env python | |
| # -*- coding: utf-8 -*- | |
| """ | |
| --A| | |
| |-a.pack | |
| |-aa.pack | |
| |-B| | |
| |-b.pack | |
| |-b.pack | |
| python commpress.py A AZIP | |
| you will get: | |
| -AZIP| | |
| |-a.pack.zip | |
| |-aa.pack.zip | |
| |-B| | |
| |-b.pack.zip | |
| |-b.pack.zip | |
| """ | |
| import os | |
| import sys | |
| import glob | |
| if __name__ == '__main__': | |
| orgin_dir = sys.argv[1] | |
| compress_dir = sys.argv[2] | |
| for file in glob.glob(os.path.join(orgin_dir, '*/*.pack')): | |
| sub_dir = file.rstrip(os.path.basename(file)) | |
| sub_dir = sub_dir.replace(orgin_dir, compress_dir, 1) | |
| if not os.path.exists(sub_dir): | |
| os.system("mkdir -p %s" % sub_dir) | |
| compress_cmd = "zip %s.zip %s" % (file.replace(orgin_dir, compress_dir, 1), file) | |
| #compress_cmd = "java -jar /home/dp/bin/dp-tools-1.0.0.jar compress -o %s.spz -i %s" % (file.replace(orgin_dir, compress_dir, 1), file) | |
| print compress_cmd | |
| os.system(compress_cmd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment