Rename files with numbers

Micah Elliott mde at micah.elliott.name
Mon Oct 31 15:03:45 EST 2005


On Oct 31, dudufigueiredo at gmail.com wrote:
> ...
> obs: the file names came this way(with spaces or apostrophes) from
> the cd i imported.

So remove them first.  Here's a possible solution::

    #! /usr/bin/env python

    import glob, os.path

    uglies = glob.glob("*.mp3")
    print 'uglies:', uglies
    pretties = []

    for ugly in uglies:
        song, ext = os.path.splitext(ugly)
        song = song.replace("'", "")
        song = song.replace(" ", "_")
        song = song.title()
        song = "The_Beatles_-_" + song[3:]
        song_ext = song + ext
        pretties.append(song_ext)

    print 'pretties:', pretties 

    # rename uglies to pretties...

-- 
_ _     ___
|V|icah |- lliott  http://micah.elliott.name  mde at micah.elliott.name
" "     """



More information about the Python-list mailing list