[Tutor] Converting Filenames to Lower case

Kent Johnson kent37 at tds.net
Sun Feb 11 03:27:01 CET 2007


Richard Querin wrote:
> Hi, I'm interested in a writing a quick python script for use on the 
> command line. I'm at the linux terminal inside a directory with a bunch 
> of files. The files have mixed case (some are .JPG and some are .jpg, 
> etc..) I'd like to be able to run a python script that will take all the 
> files in the directory I'm in and convert all the filenames and 
> extensions to lower case.
> 
> Any ideas on where to look? I've fiddled quite a bit with very basic 
> scripting but nothing to do with getting files from the current 
> directory and processing their names. Can anybody point me in the right 
> direction to get started?

os.listdir() will list the current dir. os.rename() will rename a file. 
filename.lower() converts to lower case.

Kent



More information about the Tutor mailing list