发布时间:2019-08-29 07:40:28编辑:auto阅读(1641)
看着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?
48150
46866
37784
35089
29623
26272
25211
20248
19889
18368
6021°
6719°
6204°
6183°
7296°
6135°
6254°
6727°
6703°
8082°