免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2705 | 回复: 1
打印 上一主题 下一主题

请教一个《简明python教程》里面文件zip备份的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2017-07-26 20:47 |只看该作者 |倒序浏览
运行环境windows,代码执行完目标备份路径确实有zip压缩包,不过压缩包里面是空的,cmd单独运行zip命令也是一样输出空压缩包,找不出zip命令哪里出错了,帮忙分析下可能哪里出错了?


import os
import time

source = ['E:\\Python\\back_up_test.txt']

target_dir = 'E:\\Python\\Back_up\\'

target = target_dir + os.sep + \
time.strftime('%Y%m%d%H%M%S') + '.zip'

if not os.path.exists(target_dir):
    os.mkdir(target_dir)

zip_command = 'zip -r {0} . -i {1}'.format(target,source)

print('Zip command is:')
print(zip_command)
print('Running:')
if os.system(zip_command) == 0:
    print('Successful backup to', target)
else:
    print('Backup Failed')




论坛徽章:
0
2 [报告]
发表于 2017-07-26 22:04 |只看该作者
已解决,谢谢。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP