Results 1 to 3 of 3

Thread: Convert "C:\Readm~1.txt" to "C:\Readme.txt"

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517

    Lightbulb

    Hi,

    I need to change a short filename
    to a long file name, how do I do
    that?

    Thanks!

  2. #2
    Guest
    Code:
    Public 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
        '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

  3. #3
    Addicted Member jcouture100's Avatar
    Join Date
    Aug 1999
    Posts
    141
    In case your version of Kernel32 doesn't support the 'GetLongPathName' API, here is another function you can use.

    Hope this helps.

    Code:
    Private Function sLongName(strShortName As String) As String
    '-----------------------------------------------    
    'strShortName - 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.
    '
    'USAGE: strResult = sLongName("C:\Readm~1.txt")
    '-----------------------------------------------    
    
        Dim strTemp As String   'Temporary String Holder
        Dim strNew As String    'Hold New String
        Dim intHasBS As Integer 'Has Back Slash Flag
        Dim intBS As Integer    'Back Slash Position
        If Len(strShortName) = 0 Then Exit Function
        strTemp = strShortName
    
    
        If Right$(strTemp, 1) = "\" Then
            strTemp = Left$(strTemp, Len(strTemp) - 1)
            intHasBS = True
        End If
        On Error GoTo MSGLFNnofile
    
        If InStr(strTemp, "\") Then
            strNew = ""
    
            Do While InStr(strTemp, "\")
    
                If Len(strNew) Then
                    strNew = Dir$(strTemp, 54) & "\" & strNew
                Else
                    strNew = Dir$(strTemp, 54)
    
                    If strNew = "" Then
                        sLongName = strShortName
                        Exit Function
                    End If
                End If
                On Error Resume Next
    
                For intBS = Len(strTemp) To 1 Step -1
                    If ("\" = Mid$(strTemp, intBS, 1)) Then
                        'found it
                        Exit For
                    End If
                Next intBS
                strTemp = Left$(strTemp, intBS - 1)
            Loop
            strNew = strTemp & "\" & strNew
        Else
            strNew = Dir$(strTemp, 54)
        End If
    
    MSGLFNresume:
        If intHasBS Then
            strNew = strNew & "\"
        End If
        sLongName = strNew
        Exit Function
    
    MSGLFNnofile:
        strNew = ""
        Resume MSGLFNresume
    End Function
    JC

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