Hi, let's see if you can give me a hand with this that still confused me a bit with these loops and I'm starting in python, I'm reading a directory with 20 .txt files the idea is to open each file and add a text to each one and that the 20 files have that text and once the modification is done, saving each file again would have to obtain another 20 other files with the phrase already added. I've already got stuck in this part, it's what I have written for now, also the part of saving the file, but I can't make it in a loop either so that the modification closes one by one. I can only do it individually.
import glob
import re
import os
os.chdir("Prueba/")
for file in glob.glob("*.txt"):
print(file)
f = open(file, 'r', encoding='utf-8-sig')
save = f.read()
print(save)
f.close()
You already have the cycle and the reading of the file too, you would have to open another general file with the new name and write the content of the original file plus the new text: