Created
August 8, 2012 19:36
-
-
Save owainlewis/3297959 to your computer and use it in GitHub Desktop.
File zipper
This file contains 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
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