Created
April 12, 2024 16:39
-
-
Save WillPapper/7df10adcc22eb981906c92c115e3ed04 to your computer and use it in GitHub Desktop.
Concatenate Markdown Files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
# Specify the folder path containing the Markdown files | |
folder_path = "./path-goes-here" | |
# Specify the output file path | |
output_file = "concatenated_markdown.md" | |
# Get a list of Markdown files in the specified folder | |
markdown_files = [file for file in os.listdir(folder_path) if file.endswith(".md")] | |
# Open the output file in write mode | |
with open(output_file, "w") as outfile: | |
# Iterate over each Markdown file | |
for file in markdown_files: | |
# Open the Markdown file in read mode | |
with open(os.path.join(folder_path, file), "r") as infile: | |
# Write the filename to the output file | |
outfile.write(f"# {file}\n\n") | |
# Write the contents of the Markdown file to the output file | |
outfile.write(infile.read()) | |
# Add a line break between files | |
outfile.write("\n\n---\n\n") | |
print("Concatenation complete. Output file:", output_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment