renaming files

Inyeol Lee inyeol.lee at siimage.com
Mon Jan 6 23:33:10 EST 2003


On Mon, Jan 06, 2003 at 07:58:22PM -0800, Hilbert wrote:
> Hello,
> 
> I'm new to python and trying to learn the language by doing some everyday
> tasks in it.
> I wanted to convert the following simple csh script to python:
> 
> foreach i (test-????.*)
>   mv $i `echo $i | sed 's/test/final/'`
> end
> 

import glob, os

for src in glob.glob('test-????.*'):
    os.rename(src, src.replace('test', 'final'))





More information about the Python-list mailing list