Replace and inserting strings within .txt files with the use of regex

Νίκος nikos.the.gr33k at
Sun Aug 8 04:26:31 CEST 2010

# rename ALL php files to html in every subfolder of the folder 'data'
os.rename('*.php', '*.html')               # how to tell python to
rename ALL php files to html to ALL subfolder under 'data' ?

# current path of the file to be processed
path = './data'              # this must be somehow in a loop i feel
that read every file of every subfolder

# open an html file for reading
f = open(path, 'rw')
	# read the contents of the whole file
	data =

	# replace all php tags with empty string
	data = data.replace('<?', '')
	data = data.replace('?>', '')

        # write replaced data to file
        data = f.write()

	# insert an increasing unique integer number at the very first line
of every html file processing
	comment = "<!-- %s -->"%(idnum)             # how will the number
change here an increased by one file after file?
f = f.close()

Please help i'm new to python an apart from syntx its a logic problem
as well and needs experience.

More information about the Python-list mailing list