The code I used for this solution is-
import os
def get_dir_files(dir):
all_files = os.listdir(dir)
txt_files = []
for file in all_files:
full_path = os.path.join(dir, file)
if file.find('.txt') != -1:
txt_files.append(full_path)
else:
pass
return txt_files
def get_united_file(all_files):
with open(r'C:\Users\karin\Desktop\Work\PikFix\TextCombiner\united.txt', 'w') as outfile:
for file in all_files:
with open(file) as infile:
outfile.write(infile.read() + '\n')
def main():
dir_path = r'C:\Users\karin\Desktop\Work\PikFix\TextCombiner'
all_files = get_dir_files(dir_path)
get_united_file(all_files)
if _name_ == '__main__':
main()
Watch video How To Merge Text Files in Python online without registration, duration hours minute second in high quality. This video was added by user PikFix 09 July 2022, don't forget to share it with your friends and acquaintances, it has been viewed on our site 3,395 once and liked it 54 people.