def replace_in_files(search, replace, depth=<NUM_LIT:0>, paths=None, confirm=True):
<EOL>if paths==None:<EOL><INDENT>paths = _s.dialogs.MultipleFiles('<STR_LIT>')<EOL><DEDENT>if paths == []: return<EOL>for path in paths:<EOL><INDENT>lines = read_lines(path)<EOL>if depth: N=min(len(lines),depth)<EOL>else:     N=len(lines)<EOL>for n in range(<NUM_LIT:0>,N):<EOL><INDENT>if lines[n].find(search) >= <NUM_LIT:0>:<EOL><INDENT>lines[n] = lines[n].replace(search,replace)<EOL>print(path.split(_os.path.pathsep)[-<NUM_LIT:1>]+ '<STR_LIT>'+lines[n]+'<STR_LIT:">')<EOL><DEDENT><DEDENT>if not confirm:<EOL><INDENT>_os.rename(path, path+"<STR_LIT>")<EOL>write_to_file(path, join(lines, '<STR_LIT>'))<EOL><DEDENT><DEDENT>if confirm:<EOL><INDENT>if input("<STR_LIT>")=="<STR_LIT:yes>":<EOL><INDENT>replace_in_files(search,replace,depth,paths,False)<EOL><DEDENT><DEDENT>return<EOL>
Does a line-by-line search and replace, but only up to the "depth" line.