Last active
October 6, 2016 02:29
-
-
Save rudresh-ajgaonkar/1ae7d0a3d55f13afce59225f2ff18687 to your computer and use it in GitHub Desktop.
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
from os import listdir | |
from os.path import basename, isfile, join, isdir, abspath, splitext | |
import zipfile | |
import argparse | |
def getAllFilesRecursive(root): | |
files = [join(root, f) for f in listdir(root) if isfile(join(root, f))] | |
dirs = [d for d in listdir(root) if isdir(join(root, d))] | |
for d in dirs: | |
files_in_d = getAllFilesRecursive(join(root, d)) | |
if files_in_d: | |
for f in files_in_d: | |
files.append(join(root, f)) | |
return files | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser() | |
parser.add_argument("StartDir", help="Enter Start Directory Name") | |
args = parser.parse_args() | |
if args.StartDir: | |
zippath = abspath(args.StartDir) | |
files = getAllFilesRecursive(zippath) | |
for f in files: | |
print f | |
zip = zipfile.ZipFile(basename(f)+".zip", 'w') | |
zip.write(f, basename(f)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment