Project Overview 💡
In this project, you’ll learn how to use Python to merge multiple .txt files from a folder into a single text file. You’ll use modules like glob and os to locate files and process them programmatically.
Challenge Yourself! 🚀
Before checking the solution, try writing the program on your own, using the knowledge you have so far and then check against the written guide and the complete solution provided in this article. Let’s go!
Task:
Write a Python script that:
Finds all .txt files in a folder
Put these text files in a folder and use them for this exercise.Reads the contents of each file
Merges them into a single output file, adding newlines between them
Expected Output:
The program reads all the files in the input folder:
Then, it creates a new merged_file.txt containing all the content from the .txt files:
Give it a shot! Scroll down when you're ready for the step-by-step guide.