Skip to content

Instantly share code, notes, and snippets.

@myandere
Forked from Rust1667/combine-all-md-files.py
Created November 10, 2024 09:38
Show Gist options
  • Save myandere/e9f195560e8afcfd123e26cd63701980 to your computer and use it in GitHub Desktop.
Save myandere/e9f195560e8afcfd123e26cd63701980 to your computer and use it in GitHub Desktop.
Python script used to combine all the .md files inside a folder into 1, adding the title of the file at the beginning of each of the joined sections. This script must be place inside that folder with the .md files.
outputFileName = 'single-page2'
import glob
filenames = glob.glob('*.md')
with open(outputFileName, 'w') as outfile:
for fname in filenames:
with open(fname) as infile:
fileTitleString = "\n\n\n" + "# " + fname + "\n"
outfile.write(fileTitleString)
for line in infile:
outfile.write(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment