首页 > 代码库 > 文件Move操作

文件Move操作

#coding = utf-8import  osstr1 = ‘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\nline = line.strip(‘\r\n‘)