python windows备份文件info-zip

简介:

看着python简明教程学习python,备份文件的时候老是出现问题。这里记录一下解决方案。

info-zip下载地址:http://www.info-zip.org/Zip.html#Downloads

代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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


本文转自xuzw13 51CTO博客,原文链接:http://blog.51cto.com/xuzhiwei/1288648,如需转载请自行联系原作者


相关文章
|
2天前
|
JSON 安全 数据格式
Python文件操作宝典:一步步教你玩转文件读写
Python文件操作宝典:一步步教你玩转文件读写
|
2天前
|
Python
python搭建文件服务
python搭建文件服务
7 1
|
4天前
|
前端开发 API Python
如何在Python中接收前端POST上传的文件
如何在Python中接收前端POST上传的文件
9 2
|
2天前
|
数据安全/隐私保护 Python
经验大分享:python读取yaml文件
经验大分享:python读取yaml文件
|
3天前
|
存储 Python
Python处理文件的常用代码
Python处理文件的常用代码
|
3天前
|
Python
python文件的读取与写入
python文件的读取与写入
9 0
|
4天前
|
资源调度 Windows
Windows系统yarn : 无法加载文件
Windows系统yarn : 无法加载文件
8 0
|
4天前
|
缓存 算法 Python
python文件读写讲解
python文件读写讲解
10 0
|
4天前
|
安全 Linux PHP
Python文件读写的详细讲解
Python文件读写的详细讲解
10 0
|
4天前
|
XML 存储 JavaScript
python读取xml文件详细讲解
python读取xml文件详细讲解
16 0