Skip to content

Instantly share code, notes, and snippets.

@OneGneissGuy
Created June 13, 2018 01:25
Show Gist options
  • Save OneGneissGuy/b45b4bd83a73c0793f564c219764afdd to your computer and use it in GitHub Desktop.
Save OneGneissGuy/b45b4bd83a73c0793f564c219764afdd to your computer and use it in GitHub Desktop.
unzip a directory of zip files to a destination directory using the a cli
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 6 11:51:58 2018
unzip a directory of zip files to a destination directory using the a cli
USAGE:
$ python unzip_r_packages_cli.py --indir path_to_zip_files --outdir path_to_destination
@author: jsaracen
"""
import click
import os
import zipfile
@click.command()
@click.option('--indir', default='..', prompt='Where are the zip files?',
help='The path to the zip files')
@click.option('--outdir', default='..', prompt='Where to put the unzipped files?',
help='The path for the unzipped files',
)
def unzip(indir, outdir):
"""Simple program that unpacks a directory of zip folders to a
new directory."""
file_ext = ".zip"
for root, dirs, files in os.walk(indir):
for file in files:
if file.endswith(file_ext):
path = os.path.join(root, file)
zip_ref = zipfile.ZipFile(path, 'r')
zip_ref.extractall(outdir)
zip_ref.close()
if __name__ == '__main__':
unzip()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment