当前位置:编程学习 > 网站相关 >>

备份文件中所存路径中的文件

 

<span style="font-size:18px;">#backup.py 

import os 

import time 

 

 

source = []; 

f=open('lb.txt','r')   

while True:   

    line=f.readline()   

    if len(line)==0:   

        break 

    if line[-1] == '\n': 

        line = line[:-1] 

    source.append(line)   

f.close()   

#source=[r'F:\Python\finally.py',r'D:\LDJ\LDJ\Launch.ini',r'F:\Python\dir.py'] 

target_dir=r'F:\Python\backup' 

target=target_dir + time.strftime('%Y%m%d%H%M%S')+".rar" 

zip_command="rar a %s %s"%(target, ' '.join(source)) 

if (os.system(zip_command)==0): 

    print ('Successful backup to',target) 

else: 

    print ('backup FAIlED')</span> 

 

 

摘自weishanshan00的专栏

补充:Web开发 , Python ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,