How to get the filename in the right case ?
google at mrabarnett.plus.com
Fri Sep 26 00:40:56 CEST 2008
On Sep 25, 8:38 pm, Stef Mientki <stef.mien... at gmail.com> wrote:
> I found a partial workaround that is good enough for me:
> def Get_Windows_Filename ( FileName ) :
> if os.name == 'nt' :
> File = os.path.splitext ( FileName .lower ())
> return glob.glob ( File + '.p?' )
> return FileName
> This will translate the filename into the correct case, but not the path.
> I also looked at os.path.walk, but that's too slow for me,
> because getting the path correct means I have to start at the root.
You could try win32api.GetLongPathName(...). However, I've found that
some parts of the path are converted to the correct case but other
>>> print win32api.GetLongPathName(r"c:\documents and settings\administrator\desktop\foobar.py")
c:\documents and settings\administrator\Desktop\FooBar.py
How does your solution compare to using os.listdir(...) instead of
More information about the Python-list