This question has been partially answered on this post: How to create a zip archive of a directory However, I would like some clarification, and since it was not directly related to the question, I am asking here. I am very new to python and have been absorbing all manner of text on the subject and have looked as thoroughly as possible through the answers here but I am not even sure how to ask the question.
when I call the function zipdir() I have to add parameters. The 'path' parameter is easy, but I have no idea what to put as the ziph parameter? I am not even sure what it is looking for
#!/usr/bin/env python
import os
import zipfile
toDirectory = ".\\Py\Backup"
fileName = int(time.time())
def zipdir(path, ziph):
# ziph is zipfile handle
for root, dirs, files in os.walk(path):
for file in files:
ziph.write(os.path.join(root, file))
if __name__ == '__main__':
zipf = zipfile.ZipFile('Python.zip', 'w', zipfile.ZIP_DEFLATED)
zipdir('tmp/', zipf)
zipf.close()
def fileRename():
os.renames('Python.zip', fileName + ".zip")
zipdir(toDirectory, ziph) #this is where I am not sure what to do with 'ziph'
fileRename() # Even thought he code create the zip, this does not work