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

MRAB python at mrabarnett.plus.com
Mon Aug 9 22:28:11 CEST 2010


Νίκος wrote:
> On 9 Αύγ, 10:07, Νίκος <nikos.the.gr... at gmail.com> wrote:
>> Now the code looks as follows:
>>
>> =============================
>> #!/usr/bin/python
>>
>> import re, os, sys
>>
>> id = 0  # unique page_id
>>
>> for currdir, files, dirs in os.walk('test'):
>>
>>         for f in files:
>>
>>                 if f.endswith('php'):
>>
[snip]
>>
>> I just tried to test it. I created a folder names 'test' in me 'd:\'
>> drive.
>> Then i have put to .php files inside form the original to test if it
>> would work ok for those too files before acting in the whole copy and
>> after in the original project.
>>
>> so i opened a 'cli' form my Win7 and tried
>>
>> D:\>convert.py
>>
>> D:\>
>>
>> Itsjust printed an empty line and nothign else. Why didn't even try to
>> open the folder and fiels within?
>> Syntactically it doesnt ghive me an error!
>> Somehting with os.walk() methos perhaps?
> 
> Can you help in this too please?
> 
> Now iam able to just convrt a single file 'd:\test\index.php'
> 
> But these needs to be done for ALL the php files in every subfolder.
> 
>> for currdir, files, dirs in os.walk('test'):
>>
>>         for f in files:
>>
>>                 if f.endswith('php'):
> 
> Should the above lines enter folders and find php files in each folder
> so to be edited?

I'd start by commenting-out the lines which change the files and then
add some more print statements to see which files it's finding. That
might give a clue. Only when it's fixed and finding the correct files
would I remove the additional print statements and then restore the
commented lines.



More information about the Python-list mailing list