Created
January 28, 2017 12:29
-
-
Save shiumachi/d059b80bec7c585565a3518808a97139 to your computer and use it in GitHub Desktop.
Compress multiple directories into each archives
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
# dirs_compressor.py | |
# | |
# Usage: | |
# $ python dirs_compressor.py targed_dir | |
# | |
import sys | |
import os | |
import os.path | |
import logging | |
from shutil import make_archive | |
logging.getLogger().setLevel(logging.DEBUG) | |
logging.basicConfig(format='%(asctime)s %(levelname)-4.4s [%(name)s] %(message)s') | |
def main(): | |
if len(sys.argv) != 2: | |
print("USAGE: {} [target_dir]".format(__file__)) | |
target_dir = os.path.abspath(sys.argv[1]) | |
logging.debug("target root directory: {}".format(target_dir)) | |
if os.path.isdir(target_dir) is False: | |
logging.error("{} is not a directory.".format(target_dir)) | |
file_list = os.listdir(target_dir) | |
for file_name in file_list: | |
if file_name == '.DS_Store': | |
continue | |
logging.debug("target directory: {}".format(file_name)) | |
if os.path.isdir(file_name): | |
make_archive(file_name, 'zip', file_name) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment