本文實(shí)例講述了python對(duì)指定目錄下文件進(jìn)行批量重命名的方法。分享給大家供大家參考。具體如下:
這段python代碼可對(duì)c:/temp目錄下的所有文件名為”scroll_1”文件替換為”scroll_00”
import ospath = 'c://temp'for file in os.listdir(path): if os.path.isfile(os.path.join(path,file))==True: newname = file.replace("scroll_1", "scroll_00") os.rename(os.path.join(path,file),os.path.join(path,newname)) print(file)希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選