import glob
 
# Get a list of all Markdown files in the directory
md_files = glob.glob("*.md")
 
# Sort the file list if needed
md_files.sort()
 
# Open the output file in write mode with UTF-8 encoding
with open("merged.md", "w", encoding="utf-8") as outfile:
    # Iterate over each Markdown file
    for file_name in md_files:
        # Open each file in read mode with UTF-8 encoding and read its contents
        with open(file_name, "r", encoding="utf-8") as infile:
            contents = infile.read()
            # Write the contents to the output file
            outfile.write(contents)
            outfile.write("\n")  # Add a newline between files
 
print("Files merged successfully.")