文件打包

def zip(dirname,filename):
    zip = zipfile.ZipFile(filename,'w',zipfile.ZIP_DEFLATED)
    for root,dirs,files in os.walk(dirname,topdown=False ):
        for filename in files:
            zip.write(os.path.join(root,filename).encode('gbk'))
            if len(files) == 0:
                print 'empty dir'
            zif = zipfile.ZipInfo((root+ os.sep).encode('gbk'))
            zip.writestr(zif,'')
    zip.close()

posted on 2014-07-25 10:17  leafs  阅读(159)  评论(0编辑  收藏  举报

导航