recursive file editing

TaeKyon mikalzetTogli at interfree.it
Sat Apr 3 17:42:11 EST 2004


Il Sat, 03 Apr 2004 22:35:30 +0200, Leif B. Kristensen ha scritto:

> This is a Perl one-liner:
> 
> perl -p -i -e 's/foo/bar/gi' `find ./`

Didn't work; however I realized I could just repeatedly run variations of

sed -i s/foo/bar/g *

and then rename the files with a bash script called renna.

I'm sure python could do it but I got stuck -

for file in os.walk('mydir'):
	print file[2]

gives me the names of all files 

but how do I open each with r+ mode ? 

for thing in os.walk('mydir'):
	file(thing,mode=r+)

is invalid syntax 

-- 
Michele Alzetta




More information about the Python-list mailing list