for root, _, files in os.walk(base_path): for file in files: if file.endswith('.md'): file_path = os.path.join(root, file) # 检查文件内容是否包含图片 withopen(file_path, 'r', encoding='utf-8') as f: content = f.read() if IMAGE_PATTERN.search(content): md_files_with_images.append(file_path)
return md_files_with_images
# 查找并打印结果 if __name__ == "__main__": result = find_md_with_images(base_path) if result: print(f"包含图片的Markdown文件({len(result)}个):") for md_file in result: print(md_file) else: print("未找到包含图片的Markdown文件。")