博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python压缩文件脚本
阅读量:6974 次
发布时间:2019-06-27

本文共 1035 字,大约阅读时间需要 3 分钟。

 zf.py文件

"""desc:读取配置文件config.ini压缩sourcepath路径到targetpath     并可以排除不需要压缩的文件excludefiletime:2014/4/30 12:03:42author:ggh"""import zipfile, os, configparser, timefirsttime = time.time();config = configparser.ConfigParser()config.readfp(open('config.ini'))excludefile = config.get('global', 'excludefile')ls = excludefile.split(',')def writeInZip(z, testdir):    for d in os.listdir(testdir):        if os.path.isdir(testdir+os.sep+d):            writeInZip(z, testdir+os.sep+d)        else:                        if ls.count(testdir+os.sep+d) == 0:                z.write(testdir+os.sep+d)        testdir = config.get("global","sourcepath")z = zipfile.ZipFile(config.get("global","targetpath"), 'w')writeInZip(z, testdir)z.close()        print ('Zip Success!')print (time.time() - firsttime)input("\n\nPress the enter key to exit.")

  

  

config.ini

[global]sourcepath = D:\Web(.net)targetpath = D:\Web(.net).zipexcludefile = D:\Web(.net)\Web.Config,D:\Web(.net)\Web(.net)_ln.sln

  

转载于:https://www.cnblogs.com/lovedeeply/p/3701039.html

你可能感兴趣的文章
大S变"汪太"!与汪小菲注册结婚
查看>>
使用命令行操作MySQL 及 语法
查看>>
linux常用命令
查看>>
相互递归(2)
查看>>
ubuntu16.04----jdk---install----config
查看>>
css背景图片位置:background的position(转)
查看>>
Django REST framework+Vue 打造生鲜电商项目(笔记四)
查看>>
那些堪称神器的 Chrome 插件
查看>>
html头部标签大全之header/meta/link
查看>>
英文单词记录
查看>>
16.创建文本节点createTextNode
查看>>
21.调用stop()方法停止当前所有动画效果
查看>>
匿名方法
查看>>
解析Java对象的equals()和hashCode()的使用
查看>>
关于JDK1.8 HashMap扩容部分源码分析
查看>>
Git使用手册【转】
查看>>
JSOUP如何POST只含JSON格式的数据
查看>>
LeetCode OJ:Generate Parentheses(括号生成)
查看>>
sql 各种格式
查看>>
学习javascript过程中的心得体会
查看>>