使用python3 批量修改文件名前缀
import os
def rename_folders(directory):
# 遍历指定目录下的所有文件夹
for folder_name in os.listdir(directory):
# 检查文件夹是否以“test”开头
if folder_name.startswith("test"):
# 构造新的文件夹名
new_folder_name = "1test" + folder_name[2:]
# 获取完整的旧路径和新路径
old_path = os.path.join(directory, folder_name)
new_path = os.path.join(directory, new_folder_name)
# 重命名文件夹
os.rename(old_path, new_path)
print(f"Renamed: {old_path} -> {new_path}")
# 使用示例
directory = r"E:\文件夹路径"
rename_folders(directory)
其中test为旧文件名,1test为新文件名,E:\文件夹路径根据实际情况填写