删除文件家中指定的文字
import os
def rename_files_in_folder(path, old_name, new_name):
for root, dirs, files in os.walk(path):
for file in files:
if old_name in file:
filename, extname = os.path.splitext(file)
newname = filename.replace(old_name, new_name) + extname
os.rename(os.path.join(root, file), os.path.join(root, newname))
# 使用示例
path = '/Users/文件路径/'
old_name = 'old'
new_name = 'new'
rename_files_in_folder(path, old_name, new_name)