You don't mention the format of your text files. Make sure you search the web for answers.. I recently had to change meta data on a large number of pdf's and web searches provided several ways of doing this.. from Applescript (I use Mac) to Acrobat Pro to scripts on the web (load the files to web space and run an existing cgi script.).
I know that doesn't apply to your text files.... my only point is to search for existing answers before you spend hours on your own script. My 1500 pdf files were modified in no time. I saved hours and hours of work.