/ Published in: Python

This creates a zipfile with the same name as the input file in the same location as the input file. Only does a single file.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
import zlib, zipfile, os def zipme (inputFilename): fileName = os.path.basename(inputFilename) zipFileName = os.path.basename (os.path.splitext(fileName)[0]) + '.zip' zipFilePath = os.path.dirname (inputFilename) zFile = zipfile.ZipFile(zipFilePath + '/' + zipFileName ,'w') zFile.write (inputFilename, fileName, zipfile.ZIP_DEFLATED) zFile.close() if os.stat(zipFileName): print 'zipfile created : %s' % (zipFileName) return 1 else : print 'Error creating zipfile : %s' % (zipFileName) return 0
Comments
