import os md_dir=r"E:\BlogContents\blogroot7.0\source\_posts\操作系统.md #填入markdown文件路径 mdIma_dir=r"E:\BlogContents\blogroot7.0\source\_posts\操作系统" #填入对应assets文件路径 def MdCancelIma(mdIma_dir,md_dir): for root, dirs, files in os.walk(mdIma_dir): with open(md_dir, 'r', encoding='utf-8') as md: text = md.read() for imaName in files: if text.find(imaName)==-1: print("删除的图片名为: ",imaName) path=mdIma_dir+"\\"+imaName os.remove(path) MdCancelIma(mdIma_dir,md_dir)
fordirin all_dir_list: path = all_dir+"\\"+dir if(os.path.isdir(path)): mdImg_dir_list.append(dir) a = 0 for file_name in mdImg_dir_list: md_dir = all_dir + "\\" + file_name + ".md" mdIma_dir = all_dir+"\\" + file_name MdCancelIma(mdIma_dir, md_dir)
defMdCancelIma(mdIma_dir,md_dir): for root, dirs, files in os.walk(mdIma_dir): withopen(md_dir, 'r', encoding='utf-8') as md: text = md.read() for imaName in files: if text.find(imaName)==-1: print("删除的图片名为: ",imaName) path=mdIma_dir+"\\"+imaName os.remove(path) Clean(all_dir)