Jul-19-2017, 02:16 PM
This is my current code. So the refFile will be in /some/dir/path(A-Z)/file. The filethatneedsmodified will be in /some/other/dir/path(A-Z)/filethatneedsmodified. I'm not sure how to iterate or loop over these dirs, and creating individual scripts for each file\dir obviously isn't the best way to do it. Can I use os.path.join or something to define the two paths since both file names will remain the same across the different directories?
import fileinput import sys def insert_to_line(f_name): for line in fileinput.input(f_name, inplace=True): if any(item in line for item in theList) and not line.lstrip().startswith('#'): sys.stdout.write('# {}'.format(line)) else: sys.stdout.write(line) if __name__ == '__main__': with open("/some/dir/path/file", 'r') as refFile: theList = refFile.read().splitlines() f_name = "/some/other/dir/path/filethatneedsmodified" insert_to_line(f_name)