- import os
- import time
- source='C:\\Linda\\Test\\Python\\source'
- target_dir='C:\\Linda\\Test\\Python\\backup\\'
- target=target_dir + time.strftime('%Y%m%d%H%M%S')+'.rar'
- print(target)
- rar_command = "winrar a %s %s"%(target,source)
- print (rar_command)
- if os.system(rar_command)==0:
- print ('Succeed to backup to', target)
- else:
- print ("Backup FAILED")
转载于:https://blog.51cto.com/yazi0127/947980