标签:lang star rename std with exists exception name start
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)
标签:lang star rename std with exists exception name start
原文地址:https://www.cnblogs.com/amize/p/14320358.html