Python实现批量修改对应的文件名
import os
old_names = ['1.mp4','2.mp4']
new_names = ['a.mp4','b.mp4']
path = 'D:\\test'
if len(old_names) == len(new_names):
for i in range(len(old_names)):
old_file = os.path.join(path, old_names[i])
new_file = os.path.join(path, new_names[i])
if os.path.exists(old_file):
os.rename(old_file, new_file)
print(f"Renamed {old_names[i]} to {new_names[i]}")
else:
print(f"File {old_names[i]} does not exist.")
文档信息
- 本文作者:carpe
- 本文链接:https://carpedx.com/fragment/python-batch-modify-file-names/
- 版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)