本文實例講述了python對指定目錄下文件進行批量重命名的方法。分享給大家供大家參考。具體如下:
這段python代碼可對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)
希望本文所述對大家的Python程序設計有所幫助。
新聞熱點
疑難解答