Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- def main():
- print('*** Create a zip file from multiple files using with ')
- # Name of the Directory to be zipped
- dirName = '/var/www/convert4k.com/'
- # create a ZipFile object
- with ZipFile('sampleDir.zip', 'w') as zipObj:
- # Iterate over all the files in directory
- for folderName, subfolders, filenames in os.walk(dirName):
- for filename in filenames:
- #create complete filepath of file in directory
- filePath = os.path.join(folderName, filename)
- # Add file to zip
- zipObj.write(filePath)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement