Using Regular Expresions to change .htm to .php in files

J. Cliff Dyer jcd at sdf.lonestar.org
Fri Aug 24 13:24:07 EDT 2007


Tim Williams wrote:
> On 23/08/07, sebzzz at gmail.com <sebzzz at gmail.com> wrote:
>   
>> Hi,
>>
>> I have a bunch of files that have changed from standard htm files to
>> php files but all the links inside the site are now broken because
>> they point to the .htm files while they are now .php files.
>>
>> Does anyone have an idea about how to do a simple script that changes
>> each .htm in a given file to a .php
>>
>> Thanks a lot in advance
>>
>>     
>
> Something like:
>
> Infile = open(f_name,'r+')
> Data =  Infile.read()
> InFile.write(Data.replace('.htm','.php'))
> Infile.close()
>
> :)
>   
Yeah, but you'd better make darn sure that *all* links point to .htm 
files (including external links), because you could very easily end up 
pointing to http://some.othersite.com/index.phpl

And that's just no good.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070824/cce44f63/attachment.html>


More information about the Python-list mailing list