最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python?針對(duì)在子文件夾中的md文檔實(shí)現(xiàn)批量md轉(zhuǎn)word

 更新時(shí)間:2022年04月10日 18:15:11   作者:多好一次  
這篇文章主要介紹了python?針對(duì)在子文件夾中的md文檔實(shí)現(xiàn)批量md轉(zhuǎn)word,但是自己保存的md文檔在不同的文件夾,而大部分只能實(shí)現(xiàn)同一文件夾內(nèi)的轉(zhuǎn)換,得出下列總結(jié),需要的朋友可以參考一下

前言;

最近想要實(shí)現(xiàn)批量將mardown文檔轉(zhuǎn)化為word。網(wǎng)上有很多解決的方法,但是自己保存的md文檔在不同的文件夾,而大部分只能實(shí)現(xiàn)同一文件夾內(nèi)的轉(zhuǎn)換,因此稍加改進(jìn),得出以下功能。

from glob import glob
from pathlib import Path
import os

dirs = [ d for d in glob("./**/")]

# 用在本文件夾內(nèi)則調(diào)整為下列代碼
# dirs = [ d for d in glob("./")]

# 提取所有的md文檔路徑
al1_file_pathes=[]
for dir in dirs:
? ? file_list=Path(dir).glob("*.md")
? ? for file in file_list:
? ? ? ? al1_file_pathes.append(".\\"+str(file))
? ? ? ? print(file)

? ? ? ??
# 批量轉(zhuǎn)化所有的md文檔為docx
for md_path in al1_file_pathes:
? ? doc_path=md_path.replace(".md",".docx")
? ? command_new="pandoc -s "+md_path+" -o "+doc_path?
? ? print(command_new)
? ? try:
? ? ? ? res=os.popen(command_new).readlines()
? ? ? ? if len(res)==0:
? ? ? ? ? ? print(md_path,"已經(jīng)轉(zhuǎn)化為",doc_path_2)
? ? except Exception as e:
? ? ? ? print(e)

若要將轉(zhuǎn)化的word文檔集中到python程序所在文件夾內(nèi)。

代碼如下:

from glob import glob
from pathlib import Path
import os

dirs = [d for d in glob("./**/")]

# 用在本文件夾內(nèi)則調(diào)整為下列代碼
# dirs = [ d for d in glob("./")]

# 提取所有的md文檔路徑
for dir in dirs:
? ? file_list = Path(dir).glob("*.md")
? ? for file in file_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_1
? ? ? ? try:
? ? ? ? ? ? res=os.popen(command_new_1).readlines()
? ? ? ? ? ? if len(res)==0:
? ? ? ? ? ? ? ? print(md_path,"已經(jīng)轉(zhuǎn)化為",doc_path_1)
? ? ? ? except Exception as e:
? ? ? ? ? ? print(e)

到此這篇關(guān)于python 針對(duì)在子文件夾中的md文檔實(shí)現(xiàn)批量md轉(zhuǎn)word的文章就介紹到這了,更多相關(guān)python 批量md轉(zhuǎn)word內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

高安市| 马边| 新津县| 玛纳斯县| 印江| 山东| 莒南县| 永修县| 泗水县| 莒南县| 桦川县| 揭东县| 天柱县| 醴陵市| 贺兰县| 黄石市| 东台市| 都匀市| 石首市| 平塘县| 新丰县| 玉门市| 石屏县| 客服| 南川市| 汾阳市| 湘潭市| 永川市| 宝山区| 万盛区| 乐业县| 偃师市| 浙江省| 阿鲁科尔沁旗| 介休市| 文水县| 怀远县| 海淀区| 五指山市| 南充市| 沈阳市|