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

Νίκος nikos.the.gr33k at gmail.com
Sat Aug 7 22:26:31 EDT 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 = f.read()

	# 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