Results 1 to 9 of 9

Thread: Short File Name 2 Long File Name

  1. #1

    Thread Starter
    Addicted Member jcouture100's Avatar
    Join Date
    Aug 1999
    Posts
    141

    Exclamation

    Anyone know of a way to convert a shortened filename
    into its corresponding long file name?

    Example:
    Convert: C:\MYDOCU~1\JUNKST~1\LONGFI~1.TXT
    To: C:\My Documents\Junk Stuff\Long File Name Here.txt
    JC

  2. #2

    Thread Starter
    Addicted Member jcouture100's Avatar
    Join Date
    Aug 1999
    Posts
    141

    Unhappy

    Anyone got an Idea???
    JC

  3. #3
    Addicted Member
    Join Date
    Aug 2000
    Posts
    208
    I dont think that is possible..
    But if you find, please notify me
    at:
    [email protected]

  4. #4
    Guest
    Here is how to get the long or short filename:

    Code:
    Public Declare Function GetLongPathName Lib "kernel32" Alias "GetLongPathNameA" (ByVal lpszShortPath As String, ByVal lpszLongPath As String, ByVal cchBuffer As Long) As Long
    Public Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
    
    
    Public Function GetLongFilename(ByVal sShortFilename As String) As String
        'Returns the Long Filename associated wi
        '     th sShortFilename
        Dim lRet As Long
        Dim sLongFilename As String
        'First attempt using 1024 character buff
        '     er.
        sLongFilename = String$(1024, " ")
        lRet = GetLongPathName(sShortFilename, sLongFilename, Len(sLongFilename))
        
        'If buffer is too small lRet contains bu
        '     ffer size needed.
    
    
        If lRet > Len(sLongFilename) Then
            'Increase buffer size...
            sLongFilename = String$(lRet + 1, " ")
            'and try again.
            lRet = GetLongPathName(sShortFilename, sLongFilename, Len(sLongFilename))
        End If
        
        'lRet contains the number of characters
        '     returned.
    
    
        If lRet > 0 Then
            GetLongFilename = Left$(sLongFilename, lRet)
        End If
        
    End Function
    
    
    Public Function GetShortFilename(ByVal sLongFilename As String) As String
        'Returns the Short Filename associated w
        '     ith sLongFilename
        Dim lRet As Long
        Dim sShortFilename As String
        'First attempt using 1024 character buff
        '     er.
        sShortFilename = String$(1024, " ")
        lRet = GetShortPathName(sLongFilename, sShortFilename, Len(sShortFilename))
        
        'If buffer is too small lRet contains bu
        '     ffer size needed.
    
    
        If lRet > Len(sShortFilename) Then
            'Increase buffer size...
            sShortFilename = String$(lRet + 1, " ")
            'and try again.
            lRet = GetShortPathName(sLongFilename, sShortFilename, Len(sShortFilename))
        End If
        
        'lRet contains the number of characters
        '     returned.
    
    
        If lRet > 0 Then
            GetShortFilename = Left$(sShortFilename, lRet)
        End If
        
    End Function

  5. #5

    Thread Starter
    Addicted Member jcouture100's Avatar
    Join Date
    Aug 1999
    Posts
    141

    Talking OK ... Here we go.

    Thanks everyone. I talked to Matthew about the code he provided. I couldn't get it to work. My Kernel32.dll doesn't understand the call to GetLongPathName. But, Matthew's post directed me to the site "Planet Source Code"
    which did contain another code snippet that does work.

    Thanks Matthew.

    JC.


    Here is the code:

    [code]
    Private Function sLongName(sShortName As String) As String
    'sShortName - the provided file name, fully qualified, this would usually
    'be a short file name, but can be a long file name or any combination of
    'long/short parts.
    'RETURNS: the complete long file name, or "" if an error occurs
    'an error would usually indicate that the file doesn't exist.

    Dim sTemp As String
    Dim sNew As String
    Dim iHasBS As Integer
    Dim iBS As Integer
    If Len(sShortName) = 0 Then Exit Function
    sTemp = sShortName


    If Right$(sTemp, 1) = "\" Then
    sTemp = Left$(sTemp, Len(sTemp) - 1)
    iHasBS = True
    End If
    On Error GoTo MSGLFNnofile

    If InStr(sTemp, "\") Then
    sNew = ""

    Do While InStr(sTemp, "\")

    If Len(sNew) Then
    sNew = Dir$(sTemp, 54) & "\" & sNew
    Else
    sNew = Dir$(sTemp, 54)

    If sNew = "" Then
    sLongName = sShortName
    Exit Function
    End If
    End If
    On Error Resume Next

    For iBS = Len(sTemp) To 1 Step -1
    If ("\" = Mid$(sTemp, iBS, 1)) Then
    'found it
    Exit For
    End If
    Next iBS
    sTemp = Left$(sTemp, iBS - 1)
    Loop
    sNew = sTemp & "\" & sNew
    Else
    sNew = Dir$(sTemp, 54)
    End If

    MSGLFNresume:
    If iHasBS Then
    sNew = sNew & "\"
    End If
    sLongName = sNew
    Exit Function

    MSGLFNnofile:
    sNew = ""
    Resume MSGLFNresume
    End Function
    [\code]
    JC

  6. #6
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    GetLongPathName is new to windows 2000.
    I guess someone found out it could be usefull.

  7. #7
    New Member
    Join Date
    May 2000
    Location
    sweden
    Posts
    5

    short from long...

    hej
    how can i get that long to short thing working? i need it bad!
    thanks..

  8. #8
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    Matthew Gates' code above should work to get the short path.

  9. #9
    Guest

    Re: short from long...

    Originally posted by matse
    hej
    how can i get that long to short thing working? i need it bad!
    thanks..
    Yes, it's all there matse.

    Using the code I gave above:

    Code:
    Msgbox GetShortFilename("C:\WINDOWS\Start Menu\Programs\StartUp\") 
    'returns C:\WINDOWS\STARTM~1\PROGRAMS\STARTUP\

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width