Hi José,
I am sharing a new function (code below) that I wrote the other day. There are times when you have a full path filename in some type of letter casing but you want to interact with that filename in its original casing per the way it is stored in Windows.
For example, I am integrating the GDB Debugger into Tiko and GDB returns filenames back to Tiko in UPPERCASE format. Sure, I could use that uppercase file and display it in uppercase but visually it looks much more pleasing for the filename to display within the Tiko Editor using the original case.
A filename like:
C:\DEV\TIKO_EDITOR_DEBUGGER\DEBUG-EXAMPLE\TESTFILE2.BAS
Gets converted to:
C:\dev\tiko_editor_debugger\Debug-Example\TestFile2.bas
This code might be interesting to add to AfxNova if you also find it worthwhile.
' ========================================================================================
' Get the original case filename as stored by Windows
' ========================================================================================
function AfxFilenameOriginalCase( byval filename as DWSTRING ) as DWSTRING
dim as long bufSize = 1024
dim as DWSTRING buffer = wspace(bufSize \ 2)
dim as HANDLE hfile = CreateFileW(filename, GENERIC_READ, FILE_SHARE_READ, _
null, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, null)
if hfile = INVALID_HANDLE_VALUE then exit function
dim as DWORD result = GetFinalPathNameByHandleW( hfile, *buffer, bufSize, FILE_NAME_NORMALIZED )
if (result > 0) andalso (result < bufSize) then
' Good data returned but still need to remove the mapping characters
if left(buffer, 4) = "\\?\" then buffer = mid(buffer, 5)
else
' error: could not retrieve path.
end if
' clean up
CloseHandle(hfile)
function = buffer
end function