Zip文件压缩Python3脚本

2018年7月18日14:36:45 发表评论 1,556 ℃
#!/usr/bin/pyton36
#Name:zip_file.py
#Author:amd5.cn
#Datetime: 2018-06-28 
#文件压缩
import zipfile,os,datetime

def nowTime():
    timeNow = datetime.datetime.now()
    timeStr = timeNow.strftime('%Y%m%d%H%M%S')
    return timeStr

def zipFile(files):
    baseName = os.path.basename(files)
    dirName = os.path.dirname(files)
    fileZip = zipfile.ZipFile(nowTime()+'.zip','w',zipfile.ZIP_DEFLATED)

    os.chdir(dirName)
    fileList = os.walk(baseName)
    for f,s,n in fileList:
        for name in n:
            print(os.path.join(f,name))
            fileZip.write(os.path.join(f,name))
    fileZip.close()

zipFile('/tmp/text')
精选全网爆款产品,爆品销量榜单,全场低至0元起,还有更多云产品免费试用,带你0门槛上云

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: