Skip to content

Instantly share code, notes, and snippets.

@imsakg
Last active May 2, 2022 19:09
Show Gist options
  • Save imsakg/8f75a3bfd06242eb79829f2acc22bd0d to your computer and use it in GitHub Desktop.
Save imsakg/8f75a3bfd06242eb79829f2acc22bd0d to your computer and use it in GitHub Desktop.
Import markdowns to a markdown file.
import os
from re import TEMPLATE
DIRs = sorted(os.listdir())
FOLDERs = []
FILEs = []
PREFIX = ".md"
TEMPLATE = False
for dir in DIRs:
if os.path.isdir(dir):
FOLDERs.append(dir)
else:
if dir.endswith(PREFIX):
FILEs.append(dir)
for folder in FOLDERs:
DIR = sorted(os.listdir(folder))
for file in DIR:
if file.endswith(PREFIX):
FILEs.append("{}/{}".format(folder, file))
if TEMPLATE:
if "template.md" in DIRs:
pass
# TODO
else:
with open("main.md", "w") as f:
for file in FILEs:
with open(file, "r") as f2:
f.write(f2.read())
f.write("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment