1 |
#!/usr/bin/python |
2 |
# Lowercase a list of filenames and change spaces to underscores. |
3 |
# Directories are descended recursively. |
4 |
# Dave Coffin 12/14/99 |
5 |
|
6 |
from os import * |
7 |
from os.path import * |
8 |
from string import * |
9 |
import exceptions |
10 |
import errno |
11 |
import sys |
12 |
|
13 |
def dodir(list): |
14 |
for name in list: |
15 |
if isdir(name) and not islink(name): |
16 |
orig = getcwd() |
17 |
chdir(name) |
18 |
dodir(listdir(".")) |
19 |
chdir(orig) |
20 |
new = replace(lower(name)," ","_") |
21 |
if new == name: continue |
22 |
try: |
23 |
rename(name,new) |
24 |
except OSError, (errno,message): |
25 |
print "Error renaming %s to %s: %s" % (name,new,message) |
26 |
|
27 |
list = sys.argv[1:] |
28 |
if list==[]: list=["."] |
29 |
|
30 |
dodir(list) |