使用Python重命名目录中的多个文件夹可以通过以下步骤实现:
import os
def rename_folders(directory, old_names, new_names):
for old_name, new_name in zip(old_names, new_names):
old_path = os.path.join(directory, old_name)
new_path = os.path.join(directory, new_name)
os.rename(old_path, new_path)
directory = '/path/to/directory'
old_names = ['old_folder1', 'old_folder2', 'old_folder3']
new_names = ['new_folder1', 'new_folder2', 'new_folder3']
rename_folders(directory, old_names, new_names)
这样就可以将目录中的多个文件夹按照指定的新名称进行重命名了。
注意:在使用该代码时,请确保目录路径和文件夹名称的准确性,并谨慎操作以避免意外删除或覆盖文件夹。
领取专属 10元无门槛券
手把手带您无忧上云