Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # Filename: merge_files.py
- # Author: Jeoi Reqi
- #
- # This script merges all .txt files in a specified folder into a single saved file.
- import os
- # Function to gather and merge all files into one
- def merge_files(input_folder, output_file):
- with open(output_file, 'w', encoding='utf-8') as output:
- for filename in os.listdir(input_folder):
- file_path = os.path.join(input_folder, filename)
- if os.path.isfile(file_path) and filename.endswith('.txt'):
- with open(file_path, 'r', encoding='utf-8') as file:
- output.write(file.read())
- output.write('\n') # Add a newline after each file if needed
- if __name__ == "__main__":
- input_folder_path = r'~\I-SOON\InitialTranslations\LG-TRANS1\TXT\en\Translate\translated_data' # Replace with the folder containing the .txt files
- output_file_path = r'~\I-SOON\InitialTranslations\LG-TRANS1\TXT\en\Translate\merged_output.txt' # Replace with the desired output file name
- merge_files(input_folder_path, output_file_path) # Merge the files into a single custom named file
- print("Files merged successfully.") # Terminal output
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement