change extensions

Peter Hansen peter at engcorp.com
Tue Apr 5 10:34:54 EDT 2005


Bob Then wrote:
> how can i change all files from one extension to another within a direcory?

Using Jason Orendorff's path.py module:

# change all .py files in '.' to extension .new
from path import path

for f in path('.').files():
     if f.endswith('.py'):
         f.rename(f.splitext()[0] + '.new')



Don't try the above in a folder containing useful
Python files! ;-)

-Peter



More information about the Python-list mailing list