我刚看完《Python的一个字节》,所有重要文件的备份都有问题。你知道吗
这是我的密码:
import os
import time
source = ['"C:\\My Documents"', 'C:\\Code']
target_dir = 'D:\\Backup'
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} {1}'.format(target,
' '.join(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')
虽然我使用的是windows系统,但我想我已经在系统路径环境变量中添加了C:\windows\GnuWin32\bin。Is it right? 当我在终端it shows like this中键入zip时
但当我运行程序时,结果是:
Zip command is:
zip -r D:\Backup\20170310193946.Zip "C:\My Documents" C:\Code
Running:
Backup Failed
我试了一次又一次,还是不知道为什么。你知道吗
任何帮助都将不胜感激。谢谢
目前没有回答
相关问题 更多 >
编程相关推荐