从输入文件创建zipfile
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从输入文件创建zipfile相关的知识,希望对你有一定的参考价值。
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.
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
以上是关于从输入文件创建zipfile的主要内容,如果未能解决你的问题,请参考以下文章