Skip to content

Instantly share code, notes, and snippets.

@owainlewis
Created August 8, 2012 19:36
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 owainlewis/3297959 to your computer and use it in GitHub Desktop.
Save owainlewis/3297959 to your computer and use it in GitHub Desktop.
File zipper
import shutil
import os
import sys
# Simple file zipper for concatenation of various files
class Zipper:
def __init__(self, path, *args, **kwargs):
self.files = args[0][2:]
self.path = path
# Returns a list containing the full path to each file
def toZip (self, files):
return list(map((lambda x : os.path.join(self.path, x)), files))
def zipFiles(self, dest):
with open(dest, 'wb') as destination:
for filename in self.toZip(self.files):
try:
with open(filename, 'rb') as f:
shutil.copyfileobj(f, destination)
except IOError as e:
print(e)
if __name__ == '__main__':
z = Zipper(os.getcwd(), sys.argv)
z.zipFiles(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment