# 将替换后的内容写回文件 withopen(file_path, 'w', encoding='utf-8') as file: file.write(replaced_content)
# 替换指定目录下的所有.md文件 defreplace_links_in_directory(directory): for file in os.listdir(directory): if file.endswith(".md"): file_path = os.path.join(directory, file) replace_links(file_path)