如何用python批量修改文件名(前缀)

时间:2024-03-02 18:59:59
import os
#1获取重命名的文件夹
folder_name = input(\'请输入文件夹的名字:\')

#2获取文件夹中的文件名
file_names = os.listdir(folder_name)

\'\'\'方法一
os.chdir(folder_name)
#3对获取的名字重命名
for name in file_names:
print(name)
os.rename(name,\'[mittake出品]-\'+name)\'\'\'

for name in file_names:
print(name)
old_file_name = \'./\' + folder_name + \'/\' +name
new_file_name= \'./\' + folder_name + \'/\'+\'[mittake出品]-\'+name
os.rename(old_file_name,new_file_name)