Case Renamer

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python
import re, os
NeededList = """
./Data/test SpACe.tXT
""".split('\n')
neededlist = map(lambda s:s.lower(), NeededList)
def renamer(f,dirs=0):
ftest = f.lower()
ender = ''
last = None
if dirs:
ender = '/'
last = -1
try:
i = neededlist.index(ftest+ender)
print i
if (f+ender) != NeededList[i]:
os.rename(f, NeededList[i][:last])
print 'converted to:', NeededList[i][:last],'\n'
except:
pass
for root,dirs,files in os.walk('./'):
for name in files:
file_cur = os.path.join(root,name)
print file_cur
renamer(file_cur)
for root,dirs,files in os.walk('./'):
for name in dirs:
dir_cur = os.path.join(root,name)
print dir_cur
renamer(dir_cur,1)