Is there a simple way to get the "real" case sensitive path from a all lower case path. Like the reverse of os.path.normcase.
For example, consider the directory:
c:\StackOverFlow
If I have the following snippet, how to obtain d_real?
>>> import os
>>> d = os.path.normcase('C:\\StackOverFlow') # convert to lower case
>>> d
'c:\\stackoverflow'
>>> d_real = ... # should give 'C:\StackOverFlow' with the correct case
I wouldn't consider this solution simple, but what you can to is:
import os
d = os.path.normcase('C:\\StackOverFlow')
files = os.listdir(os.path.dirname(d))
for f in files:
if not d.endswith(f.lower()):
continue
else
real_d = os.path.join(os.path.dirname(d), f)
It's probably not efficient (depending on the number of files in the directory). It needs tweaking for the path-components (my solution really only corrects the case of the file name and doesn't care about the directory names). Also, maybe os.walk
could be helpful to traverse down the tree.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With