发布时间:2019-08-29 07:40:28编辑:auto阅读(1992)
看着python简明教程学习python,备份文件的时候老是出现问题。这里记录一下解决方案。
info-zip下载地址:http://www.info-zip.org/Zip.html#Downloads
代码如下:
import os
import time
#1.需要备份的文件或者文件夹
source = ['d:\\sll','D:\\download']
#2.需要备份的存放目录
target_dir = 'd:\\pyback\\'
#3要压缩的文件
target = target_dir + time.strftime('%Y%m%d%H%M%S')+'.zip'
print target
zip_command = "zip -qr %s %s" % (target,' '.join(source))
print zip_command
if os.system(zip_command) == 0:
print 'Successfull back to',target
else:
print 'backup failed'这里要压缩的文件不需要'%s',这样windows下无法创建文件。
然后运行 “python back.py”压缩成功info-zip
上一篇: python笔记--磁盘使用率
下一篇: python类中为什么要self?
51265
50705
41306
38125
32582
29489
28346
23207
23178
21502
1577°
2296°
1906°
1847°
2157°
1890°
2576°
4317°
4167°
2973°