【发布时间】:2021-12-03 22:36:36
【问题描述】:
我有一个 python 函数,它可以从文件夹中提取我所有的 .md 文件并将它们全部转换为 html 文件,同时还制作一个大的降价文件。
import glob
import os
import markdown
def main():
file_list_md = glob.glob(os.path.join("\\\\servermame\\prod_help_file\\input\\*", "*.md"))
file_list_html = glob.glob(os.path.join("\\\\servername\\prod_help_file\\input\\*", "*.html"))
config = {
'extra': {
'footnotes': {
'UNIQUE_IDS': True
}
}
}
with open('\\\\servername\\prod_help_file\\bigfile.md', 'w') as output:
for x in file_list_md:
with open(x, 'r') as body:
text = body.read()
html = markdown.markdown(text, extensions=['extra'], extension_configs=config)
output.write(html)
y = x.replace('input', 'output')
k = y.replace('.md', '.html')
with open(k, 'w') as output2:
with open(file_list_html[0], 'r') as head:
text = head.read()
output2.write(text)
output2.write(html)
with open(file_list_html[1], 'r') as foot:
text = foot.read()
output2.write(text)
if __name__ == "__main__":
main()
但我必须使用完整目录并按顺序保存它们,这些文件有 5 个数字和一个下划线,如下所示:
"C:\\servername\prod_help_file\input\10809_file.md"
我希望输出文件是这样的:
"C:\\servername\prod_help_file\output\file.md"
没有数字或下划线。有什么办法可以去掉这5个数字和下划线吗?
【问题讨论】: