Make all files extension lower by a given directory name

Discussion in 'Python' started by Tiefeng Wu, Nov 1, 2006.

  1. Tiefeng Wu

    Tiefeng Wu Guest

    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/
     
    Tiefeng Wu, Nov 1, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Merrigan
    Replies:
    6
    Views:
    303
    Merrigan
    May 1, 2006
  2. Tim Chase
    Replies:
    1
    Views:
    334
    Martin Miller
    Nov 3, 2006
  3. chiara
    Replies:
    6
    Views:
    501
    Barry Schwarz
    Oct 6, 2005
  4. John B. Matthews
    Replies:
    2
    Views:
    531
    John B. Matthews
    Aug 22, 2009
  5. Dag Sunde
    Replies:
    8
    Views:
    115
Loading...

Share This Page