Skip to content

Instantly share code, notes, and snippets.

@rudresh-ajgaonkar
Last active October 6, 2016 02:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rudresh-ajgaonkar/1ae7d0a3d55f13afce59225f2ff18687 to your computer and use it in GitHub Desktop.
Save rudresh-ajgaonkar/1ae7d0a3d55f13afce59225f2ff18687 to your computer and use it in GitHub Desktop.
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