renaming files

Inyeol Lee inyeol.lee at
Tue Jan 7 05:33:10 CET 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