python 批量重命名
2021-03-05 17:30
标签:lang star rename std with exists exception name start python 批量重命名 标签:lang star rename std with exists exception name start 原文地址:https://www.cnblogs.com/amize/p/14320358.html
import os
def remove_filename(path_dir, start, end):
files = [f for f in os.listdir(path_dir) if f.startswith(start) and f.endswith(end)]
for file_name in files:
new_file_name= file_name.replace(start,‘‘)
os.chdir(path_dir)
try:
if not os.path.exists(new_file_name):
print(file_name, ‘ changed to ‘, new_file_name)
os.rename(file_name, new_file_name)
except Exception as e:
print(e)
上一篇:python快速下载第三方包
下一篇:Java常用框架