將文件夾中的.jsp重命名為.html
import os def rename(path): files = os.listdir(path) for file in files: dir = os.path.join(path, file)
# 檢測是否為文件夾,如果是,則遞歸 if os.path.isdir(dir): rename(dir) continue file_split = file.split('.') if file_split[1] == "jsp": new_dir = os.path.join(path,file_split[0]+'.html') os.rename(dir,new_dir) rename(os.path.dirname(__file__))