整个脚本已经可以运行,只是有不理解的地方
脚本中对zip_command = "rar a %s %s"%(target,' '.join(source))的理解不到位,希望有理解的人能解释一下原理。
#!/usr/bin/python
# Filename:backupup_ver5.py
import os
import time
source = ['D:\\python-source\\nihao.txt']
target_dir = 'D:\\python-backup\\'
today = target_dir + time.strftime('%Y%m%d')
now = time.strftime('%H%M%S')
comment = input('Enter a comment -->')
if len(comment) == 0:
target = today + os.sep + now + '.zip'
else:
target = today + os.sep + now + '_' +\
comment.replace(' ','_') + '.zip'
if not os.path.exists(today):
os.mkdir(today)
print('Successfully create directory',today)
zip_command = "rar a %s %s"%(target,' '.join(source))
if os.system(zip_command) == 0:
print('Successful backup to',target)
else:
print('Backup FAILE')
收到一只叮咚
相关分类