python 从filelist.txt中拷贝文件到另一文件夹中

 1 #! python  
 2 #coding:utf-8  
 3   
 4 ##!/usr/bin/python  
 5 # Filename : fileCp.py  
 6 import sys  
 7 import os    
 8 import shutil   
 9   
10 fileList='filelist.txt'  
11 targetDir='files'  
12   
13 filedir = open(fileList)  
14 line = filedir.readline()  
15 log = open('running.log','w')  
16 while line:  
17         line = line.strip('
');  #如果从VS的fscanf(fp, "%s
", buf)生成的list需要使用 line.strip('
')
18         basename =  os.path.basename(line)  
19         exists = os.path.exists(line)  
20         if exists :  
21             print 'copy '+line+' to '+os.getcwd()+'/'+targetDir+'/'+basename  
22             log.write('copy '+line+' to '+os.getcwd()+'/'+targetDir+'/'+basename+'
')  
23             shutil.copy(line,targetDir+'/'+basename)  
24         else:  
25             print line+' not exists'  
26             log.write(line+' not exists'+'
')  
27         line = filedir.readline()  
28 log.close()  
原文地址:https://www.cnblogs.com/haiyang21/p/7239622.html