使用Python在Windows下调用W

发布时间:2019-08-26 07:19:56编辑:auto阅读(1936)

    1. import os  
    2. import time  
    3.  
    4. source='C:\\Linda\\Test\\Python\\source' 
    5. target_dir='C:\\Linda\\Test\\Python\\backup\\' 
    6.  
    7. target=target_dir + time.strftime('%Y%m%d%H%M%S')+'.rar' 
    8.  
    9. print(target)  
    10.  
    11. rar_command = "winrar a %s %s"%(target,source)  
    12. print (rar_command)  
    13.  
    14. if os.system(rar_command)==0:  
    15.     print ('Succeed to backup to', target)  
    16. else:  
    17.     print ("Backup FAILED"

关键字