So im needing a code to search for the word "hello" in all txt files in currentdir. if the txt file dont have the text "hello" then simply write "hello" into that file. hmmm well thats all i need.
I'm writing out of my head here, so this code will most likely not work, but you'll get the picture.
Code:
import os, string
for x in os.listdir("."):
work_str = open(x,"r").read()
if string.find(work_str,"hello") == -1:
open(x,"a").append("hello")
else: pass
OK, its probably the buggiest code your computer has ever seen, but you get my point (I hope Oh, and, look the code through before running it, so it doesn't kill your computer or anything.. No guarantees
PS, I opened the file twice, perhaps there's a nicer way to do this. DS