import os
import time
source = 'D:\\temp'
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 = ('rar a {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')
python中这个备份程序是怎么执行的啊,是哪句话调用了winrar啊
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- zt3032 2017-08-22 09:49关注
import os
import time
source = 'D:\temp' #要打包的目录
target_dir = 'D:\Backup' #备份的目录
target = target_dir + os.sep + time.strftime('%Y%m%d%H%M%S') + '.zip' #备份文件目录名称 'D:\Backup\20170822174500.zip'
if not os.path.exists(target_dir): #判断目录是否存在
os.mkdir(target_dir) #不存在则先创建D:\Backup 文件夹
zip_command = ('rar a {0} {1} '.format(target, ''.join(source))) #拼压缩命令 rar a D:\Backup\20170822174500.zip D:\temp
print('Zip command is:')
print(zip_command)
print('Running:')
if os.system(zip_command) == 0: #这块执行真正的命令 os.system(args) 这个函数是python执行系统函数的接口,返回0表示执行成功,否则失败
print('Successful backup to', target)
else:
print('Backup FAILED')望采纳!!!
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 delta降尺度计算的一些细节,有偿
- ¥15 Arduino红外遥控代码有问题
- ¥15 数值计算离散正交多项式
- ¥30 数值计算均差系数编程
- ¥15 redis-full-check比较 两个集群的数据出错
- ¥15 Matlab编程问题
- ¥15 训练的多模态特征融合模型准确度很低怎么办
- ¥15 kylin启动报错log4j类冲突
- ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
- ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序