发布时间:2019-08-29 07:40:28编辑:auto阅读(2102)
看着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?
51949
51742
42040
38881
33372
30337
28981
23997
23911
22268
444°
2620°
3318°
2752°
2733°
3503°
2696°
3525°
5818°
5604°