Make all files extension lower by a given directory name

Tiefeng Wu icebergwtf at yahoo.com.cn
Wed Nov 1 11:35:19 CET 2006


Hello everybody!
I need make all files extension to lower by a given directory.
Here is my solution:

import os

def make_all_file_ext_lower(root):
    for path, subdirs, files in os.walk(root):
        for file in files:
            (name, ext) = os.path.splitext(file)
            fullname = name[:len(name) - 1] + ext.lower()
            os.rename(os.path.join(path, file), os.path.join(path, fullname))

I know this code is lame and maybe someone can give a better?
Just for learning, thanks! :)

wutiefeng
06-11-01


		
___________________________________________________________ 
雅虎免费邮箱-3.5G容量,20M附件 
http://cn.mail.yahoo.com/



More information about the Python-list mailing list