python压缩文件脚本
2020-11-22 21:27
阅读:626
标签:des com blog class div code c log t tar sp
zf.py文件
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
""" desc:读取配置文件config.ini压缩sourcepath路径到targetpath 并可以排除不需要压缩的文件excludefile
time:2014/4/30 12:03:42 author:ggh """ import
zipfile, os, configparser, time
firsttime =
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
?
1
2
3
4
|
[ global ]
sourcepath =
D:\Web(.net)
targetpath =
D:\Web(.net). zip
excludefile =
D:\Web(.net)\Web.Config,D:\Web(.net)\Web(.net)_ln.sln
|
python压缩文件脚本,搜素材,soscw.com
python压缩文件脚本
标签:des com blog class div code c log t tar sp
原文地址:http://www.cnblogs.com/lovedeeply/p/3701039.html
上一篇:js实现照片墙功能
评论
亲,登录后才可以留言!