import os main_directory = './' participant_dirs = range(1, 34) output_file = os.path.join(main_directory, 'merged_notes.txt') with open(output_file, 'w') as outfile: for participant in participant_dirs: participant_dir = os.path.join(main_directory, str(participant)) if os.path.exists(participant_dir): for filename in os.listdir(participant_dir): if filename.endswith('.txt'): file_path = os.path.join(participant_dir, filename) outfile.write(f"\n\n--- Participant {participant} ---\n\n") with open(file_path, 'r') as infile: outfile.write(infile.read()) else: print(f"Directory {participant_dir} does not exist.") print("Merging complete. Check the merged_notes.txt file in the main directory.")