- 帖子
- 3
- 精华
- 0
- 积分
- 13
- 阅读权限
- 10
- 注册时间
- 2017-8-23
- 最后登录
- 2017-8-26
|
#代码如下
import os
import time
source = ['"D:\\ppp300"']
target_dir = 'D:\\pybackup'
if not os.path.exists(target_dir):
os.mkdir(target_dir)
today = target_dir + os.sep + time.strftime('%Y%m%d')
now = time.strftime('%H%M%S')
target = time = os.sep + now + '.rar'
if not os.path.exists(today):
os.mkdir(today)
print('Successful created directory', today)
rar_command = "rar a -r {0} {1}".format(target,
' '.join(source))
print('Rar command is:')
print(rar_command)
print('Running:')
if os.system(rar_command) == 0:
print('Successful backup to', target)
else:
print('Backup FAILED')
|
|