fixCasingOfPath(fullPath) because WinTitle is case-sensitive or to normalize paths

Post your working scripts, libraries and tools for AHK v1.1 and older
MrDoge
Posts: 151
Joined: 27 Apr 2020, 21:29

fixCasingOfPath(fullPath) because WinTitle is case-sensitive or to normalize paths

Post by MrDoge » 12 Jan 2022, 14:46

fix casing of path because vscode (sometimes) doesn't show correct casing, and it messed up my WinTitle matching to reRun active .ahk file

Code: Select all

MsgBox % fixCasingOfPath("c:\autohotkey_2.0-beta.3") ; C:\AutoHotkey_2.0-beta.3

fixCasingOfPath(fullPath) {
    DllCall("shell32\SHParseDisplayName", "Ptr", &fullPath, "Uint", 0, "Ptr*", pIDL, "Uint", 0, "Uint", 0)
    VarSetCapacity(pszPath, 600) ;600 was a random number
    DllCall("shell32\SHGetPathFromIDListW", "Ptr", pIDL, "Ptr", &pszPath)
    DllCall("ole32\CoTaskMemFree", "Ptr", pIDL) ;free memory
    return StrGet(&pszPath+0)
}
if your goal is to normalize a path, it can be used in conjunction with:

Code: Select all

GetFullPathName(path) { ;https://www.autohotkey.com/boards/viewtopic.php?t=67050#p289536
  cc := DllCall("GetFullPathNameW", "str", path, "uint", 0, "ptr", 0, "ptr", 0, "uint")
  VarSetCapacity(buf, cc*2)
  DllCall("GetFullPathNameW", "str", path, "uint", cc, "ptr", &buf, "ptr", 0, "uint")

  return StrGet(&buf)
}

Code: Select all

activeEditorLong:="C:\autoHotkey_2.0-beta.3\你好,世界!.ah2" ;since it's SHGetPathFromIDListW instead of SHGetPathFromIDListA, it works..
activeEditorLong:=GetFullPathName(activeEditorLong)
activeEditorLong:=fixCasingOfPath(activeEditorLong)

Return to “Scripts and Functions (v1)”