Untitled

 avatar
unknown
plain_text
a year ago
710 B
8
Indexable
import os

# The directory containing the text files
directory = '/path/to/your/directory'

# The line of text you want to add
text_to_add = '@NotNull'

# Iterate through all files in the directory
for filename in os.listdir(directory):
    if filename.endswith('.txt'):  # Check if the file is a text file
        file_path = os.path.join(directory, filename)
        with open(file_path, 'r') as file:
            lines = file.readlines()

        with open(file_path, 'w') as file:
            add_text = True
            for line in lines:
                if "@" in line and add_text:
                    file.write(text_to_add + '\n')
                    add_text = False
                file.write(line)
Editor is loading...