#!/usr/bin/env python __doc__ = """\ """ import os.path import fnmatch import fileinput import re import string def callback(arg, directory, files): for file in files: if fnmatch.fnmatch(file,arg): for line in fileinput.input(os.path.abspath(os.path.join(directory, file)),inplace=1): #for oldstring in ('http://autosourcenow.com/Page/', 'http://www.autosourcenow.com/Page/'): for oldstring in ('http://autosourcenow.com/', 'http://www.autosourcenow.com/'): searchstring = '.*' + oldstring + '.*' if re.search(searchstring, line): # I changed * to .* but it would probably work without this if line = string.replace(line,oldstring,'../') # old string , new string print line, if __name__ == '__main__': # f = open('test.url', 'w') # f.write ('Old old olddata Olddata') # f.close() os.path.walk(".", callback, "*.htm") # Directory you are looking under, and file pattern