Python读取文件夹中的文件名并修改
2020-01-06 本文已影响0人
每天必吃香菜
Python读取文件夹中的文件名并修改:
import os
def readname():
filePath = 'F:\\STR\EAST\\EAST-master\\data\\ocr\\icdar2015\\ch4_training_localization_transcription_gt'
names = os.listdir(filePath)
return names
filepath2='F:\\STR\EAST\\EAST-master\\data\\ocr\\icdar2015\\ch4_training_localization_transcription_gt'
if __name__ == "__main__":
names = readname()
print(names)
for name in names:
print(name)
i=1
for name in names:
newname="img_"+str(i)+'.txt'
i+=1
print(newname)
os.rename(filepath2+'\\'+name,filepath2+'\\'+newname)