Getting correct file names under Windows

Eric Brunel eric.brunel at pragmadev.com
Thu Feb 7 18:25:25 CET 2002


Hi all,

Windows case insensitivity striked again: I've got a Python/Tkinter program
that uses the new tk function named tk_chooseDirectory (new in Tk 8.3),
displaying a directory selection dialog. For some reason, this function
insists in returning the selected directory all uppercase. Unfortunately,
even if Windows does not care about case, we definetely don't want that: the
disk we work on is mounted from a Samba Unix - therefore case sensitive -
server, and we want to use the same file names on both environments.
So I tried to get the "real" file name, i.e. the one that is defined on
Unix, and the one I actually see in Windows Explorer or DOS windows. I
didn't succeed...

Does anybody know any way to get the "real" name of a file or directory
under Windows, i.e. the one that Explorer displays?

TIA
 - eric -

PS: For those interested, during my tests, I stumbled on an "interesting"
thing...
If I issue at the DOS prompt something like:
cd PYTHON21
and then:
cd
it prints the correct directory name (C:\Python21), even if I typed it the
"wrong" way in the cd.
Now, if I do exactly the same thing via Python:
>>> import os
>>> os.chdir('PYTHON21')
>>> os.getcwd()
the result is 'C:\\PYTHON21'.
Even if I do an os.popen('cd', 'r').readline(), it returns the same thing!
And apparently, the case I use in the chdir is kinda "sticky":
>>> os.chdir('pYtHoN21')
>>> os.getcwd()
'C:\\pYtHoN21'
>>> os.popen('cd').readline()
'C:\\pYtHoN21'
This is *weird*!





More information about the Python-list mailing list