12
12
for ch in invalid: name = name.replace(ch, '_')
15
def caseInsensitivePath(path, RET_FOUND=False):
17
Get a case insensitive path on a case sensitive system
19
RET_FOUND is for internal use only, to avoid too many calls to os.path.exists
21
getCaseInsensitivePath('/hOmE/mE/sOmEpAtH.tXt')
23
import os # todo, what happens with no os?
26
if RET_FOUND: ret = path, True
30
if path=='' or os.path.exists(path):
31
if RET_FOUND: ret = path, True
35
f = os.path.basename(path) # f may be a directory or a file
36
d = os.path.dirname(path)
39
if not f: # dir ends with a slash?
40
if len(d) < len(path):
41
suffix = path[:len(path)-len(d)]
43
f = os.path.basename(d)
44
d = os.path.dirname(d)
46
if not os.path.exists(d):
47
d, found = caseInsensitivePath(d, True)
50
if RET_FOUND: ret = path, False
54
# at this point, the directory exists but not the file
56
try: # we are expecting 'd' to be a directory, but it could be a file
59
if RET_FOUND: ret = path, False
64
try: f_nocase = [fl for fl in files if fl.lower() == f_low][0]
65
except: f_nocase = None
68
if RET_FOUND: ret = os.path.join(d, f_nocase) + suffix, True
69
else: ret = os.path.join(d, f_nocase) + suffix
72
if RET_FOUND: ret = path, False
74
return ret # cant find the right one, just return the path as is.
b'\\ No newline at end of file'