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

Peter Otten __peter__ at web.de
Mon Aug 9 09:38:34 CEST 2010


Νίκος wrote:

> Now the code looks as follows:

> for currdir, files, dirs in os.walk('test'):
> 
>         for f in files:
> 
>                 if f.endswith('php'):
> 
>                         # get abs path to filename
>                         src_f = join(currdir, f)

> 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?

If there is a folder D:\test and it does contain some PHP files (double-
check!) the extension could be upper-case. Try

if f.lower().endswith("php"): ...

or

php_files = fnmatch.filter(files, "*.php")
for f in php_files: ...

Peter




More information about the Python-list mailing list