#coding = utf-8 import os str1 = ‘d:/v3/‘ str2 = ‘d:/v3/‘ fobj = open(‘D:/V3/txt/1.txt‘,‘rb‘) line = fobj.readline() while line: if(line.find(‘a‘) > 0): strsha1 = line.split(‘\\‘) strsha1 = strsha1[-1] # print str1+strsha1 os.rename(line, str1+strsha1) elif(line.find(‘b‘) > 0): strmd5 = line.split(‘\\‘) strmd5 = strmd5[-1] # print str2+strmd5 os.rename(line,str2+strmd5) else: print(line) line = fobj.readline() fobj.close()
如果报error123错误,则需要添加如下代码
#sometimes filter \n or \r\n line = line.strip(‘\r\n‘)
原文地址:http://www.cnblogs.com/xiaobaichuangtianxia/p/3804372.html