Short --> Long path name?

  • 17 years ago

    I've found dozens of articles and tutorials and APIs on getting the short path name, but I want to know how in the world I get the long path name from the short path name.


    In my app, I have it display the file name (less path and extension) in the title bar, similar to word. It works beautifully when you load a file after opening the app. When you double-click an associated file from explorer though, it passes the short path name, causing most files to have that annoying ~1 at the end of them. I want to get rid of that and have it show the entire thing.


    I know there's probably some super simple answer that I'm overlooking, but I guess I'm just too swamped with other concerns right now to think of it.

  • 17 years ago

    i had exactly the same problem a while ago and i fixed it by putting this in the registry for the open command:
    "C:\MY DOCUMENTS\ALEXANDER\YETI PET\YETI PET.exe" "%1"
    not
    C:\MY DOCUMENTS\ALEXANDER\YETI PET\YETI PET.exe %1
    that will certainly get the full filename. i tried using the GetFullPathName API function but i think that just maps the path (App.Path & FileName) and not what you want.

  • 17 years ago

    Code:

    Private Declare Function GetLongPathName Lib "kernel32" Alias "GetLongPathNameA" (ByVal lpszShortPath As String, ByVal lpszLongPath As String, ByVal cchBuffer As Long) As Long


    Public Function GetLongFilename(ByVal sShortFilename As String) As String
    Dim lRet As Long
    Dim sLongFilename As String
       sLongFilename = String$(1024, " ")
       lRet = GetLongPathName(sShortFilename, sLongFilename, Len(sLongFilename))


    If lRet > Len(sLongFilename) Then
       sLongFilename = String$(lRet + 1, " ")
       lRet = GetLongPathName(sShortFilename, sLongFilename, Len(sLongFilename))
    End If


    If lRet > 0 Then
       GetLongFilename = Left$(sLongFilename, lRet)
    End If


    End Function

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Some people, when confronted with a problem, think "I know, I’ll use regular expressions." Now they have two problems.” - Jamie Zawinski