发布时间:2019-08-29 07:40:28编辑:auto阅读(2445)
看着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?
54451
41218
35749
31294
26197
25914
24417
19950
15996
15433
2323°
2117°
2213°
2343°
2302°
2510°
2456°
2268°
2349°
2317°