import os path =r'E:\CRM\phone\call' path2= r'E:\CRM\phone\result' for root,dirs,files in os.walk(path): for fn in files: #print fn name=fn.split('.') wroute1 = r'%s'%path+'\\'+fn wroute2 = r'%s'%path2+'\\'+name+'jieguo.txt' file1 = open(wroute1,'r') file2 = open(wroute2,'w+') for k in file1.readlines(): if 'com' in k : list1 = k.strip().split('\t') urs = list1 #print urs call_1 = list1 if call_1.find("打DM电话")!=-1: file2.write('%s\t%s\n'%(urs,call_1)) file2.close() ''' name_list = for name in name_list: wroute1 = r'E:\CRM\phone\call\%s.txt'%name wroute2 = r'E:\CRM\phone\call\%s'%name+'jieguo.txt' #print wroute1,wroute2 file1 = open(wroute1,'r') file2 = open(wroute2,'w+') for k in file1.readlines(): if 'com' in k : list1 = k.strip().split('\t') urs = list1 #print urs call_1 = list1 if call_1.find("打DM电话")!=-1: file2.write('%s\t%s\n'%(urs,call_1)) file2.close() '''