Chinaunix

标题: 请教一个《简明python教程》里面文件zip备份的问题 [打印本页]

作者: 张文松    时间: 2017-07-26 20:47
标题: 请教一个《简明python教程》里面文件zip备份的问题
运行环境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')





作者: 张文松    时间: 2017-07-26 22:04
已解决,谢谢。





欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2