lowers the case of all the items found in a specified directory
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15  | import os
import shutil
def lower_names(dir):
    assert(os.path.isdir(dir))
    [os.rename( os.path.join( dir, file ),
            os.path.join( dir, file.lower() ))
                            for file in os.listdir(dir)]
def get_dir():
    input = raw_input('Enter Directory Name: ')
    return input
if __name__ == '__main__':
    dir = get_dir()
    lower_names(dir)
 | 
I wrote this because my friend had a directory of html files where the first letter of each file was upper case, and these files were referenced with all lower case file names in the html they contained. I used a lot of the newer features of Python to whip up this script.
    Tags: files
  
  
Download
Copy to clipboard
Improved version. Here is an improved version that uses generators in Python 2.3. This version will also handle subdirectories and directory names.