python怎么实现批量md转word(python,Word,开发技术)

时间:2024-05-05 19:34:26 作者 : 石家庄SEO 分类 : 开发技术
  • TAG :

前言;

最近想要实现批量将mardown文档转化为word。网上有很多解决的方法,但是自己保存的md文档在不同的文件夹,而大部分只能实现同一文件夹内的转换,因此稍加改进,得出以下功能。

python怎么实现批量md转word

python怎么实现批量md转word

python怎么实现批量md转word

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的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:python怎么实现自动整理文件下一篇:

11 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18