python怎么实现批量md转word
导读:本文共1206.5字符,通常情况下阅读需要4分钟。同时您也可以点击右侧朗读,来听本文内容。按键盘←(左) →(右) 方向键可以翻页。
摘要: 前言;最近想要实现批量将mardown文档转化为word。网上有很多解决的方法,但是自己保存的md文档在不同的文件夹,而大部分只能实现同一文件夹内的转换,因此稍加改进,得出以下功能。fromglobimportglobfrompathlibimportPathimportosdirs=[dfordinglob("./**/")]#... ...
音频解说
目录
(为您整理了一些要点),点击可以直达。前言;
最近想要实现批量将mardown文档转化为word。网上有很多解决的方法,但是自己保存的md文档在不同的文件夹,而大部分只能实现同一文件夹内的转换,因此稍加改进,得出以下功能。
fromglobimportglobfrompathlibimportPathimportosdirs=[dfordinglob("./**/")]#用在本文件夹内则调整为下列代码#dirs=[dfordinglob("./")]#提取所有的md文档路径al1_file_pathes=[]fordirindirs:file_list=Path(dir).glob("*.md")forfileinfile_list:al1_file_pathes.append(".\\"+str(file))print(file)#批量转化所有的md文档为docxformd_pathinal1_file_pathes:doc_path=md_path.replace(".md",".docx")command_new="pandoc-s"+md_path+"-o"+doc_pathprint(command_new)try:res=os.popen(command_new).readlines()iflen(res)==0:print(md_path,"已经转化为",doc_path_2)exceptExceptionase:print(e)
若要将转化的word文档集中到python程序所在文件夹内。
代码如下:
fromglobimportglobfrompathlibimportPathimportosdirs=[dfordinglob("./**/")]#用在本文件夹内则调整为下列代码#dirs=[dfordinglob("./")]#提取所有的md文档路径fordirindirs:file_list=Path(dir).glob("*.md")forfileinfile_list:md_path=".\\"+str(file)doc_path_1=os.path.split(file)[1].replace(".md",".docx")command_new_1="pandoc-s"+md_path+"-o"+doc_path_1try:res=os.popen(command_new_1).readlines()iflen(res)==0:print(md_path,"已经转化为",doc_path_1)exceptExceptionase:print(e)
</div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:
python怎么实现批量md转word的详细内容,希望对您有所帮助,信息来源于网络。