Python batch modify file names under the folder

the code

import os


fileDir = "C:/WorkSpace/Cloth" #文件夹路径  文件路径分隔 使用/ 或者\\
fileList = os.listdir(fileDir) 
os.chdir(fileDir) #进入当前要操作的文件目录
for fileName in fileList :
    print(fileName)
    NewName = fileName.replace("nc_","bs_")
    print(NewName)
    os.rename(fileName,NewName) 

The above is just a simple implementation, and different codes are implemented for different needs, and the general idea is the same.

Guess you like

Origin blog.csdn.net/a940659387/article/details/128803876