Windows, filename in right case, can it be done simpler ?

S

Stef Mientki

hello,

when getting a breakpoint from pdb and similar packages,
on Windows, the filename is given in lowercase.
For the caption of my editor, I need the filename in the correct case.
The function below does work reasonable well (path is not in the correct
case),
but I find it weird and much too difficult.
Does anyone has a better solution ?

thanks,
Stef Mientki


# ***********************************************************************
# ***********************************************************************
def Get_PDB_Windows_Filename ( FileName ) :
"""
On windows systems,
Translates the Filename to the correct case
the preceding absolute or relative path is converted to lower case !!
Used to translate filenames coming from PDB and similar packages
On other OS, it just returns the unmodified string
"""
if os.name == 'nt' :

# path will be translated to lowercase
# and we want only forward slashes
FileName = FileName.lower ().replace ( '\\', '/' )

# Do a search with some degrees of freedom
# otherwise glob.glob just returns the original string !!
Result = glob.glob ( FileName [:-1] + '*')

if Result:
for R in Result :
if R.lower().replace( '\\', '/' ) == FileName :
return R.replace ( '\\', '/' )
return FileName
# ***********************************************************************
 
M

Martin v. Löwis

Does anyone has a better solution ?

If you have pythonwin, you can use win32file.FindFilesW, passing
the lower-cased file name.

Regards,
Martin
 
S

Stef Mientki

Martin said:
If you have pythonwin, you can use win32file.FindFilesW, passing
the lower-cased file name.
Thanks Martin,
seems to work great.

cheers,
Stef
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top