Results 1 to 2 of 2

Thread: Old/New file naming issue.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Location
    Atlanta
    Posts
    104
    I've noticed something somewhat odd. It's not so much odd, because I know why it happens, as it is annoying.

    When you open a file via the commondialog control it will give the full (long filename) path and filename.

    C:\My Documents\My Documents\Long.Filename.txt

    If you have an application that opens a file via the command$ (command line) you are able to drop a file onto that application and it will automatically put that filename into the command line. But it appears in the old 8 char dos filename format.

    C:\MYDOCU~1\MYDOCU~1\LONG.FIL~1.TXT

    This is fine, because it still opens the file properly, but I have the information stored in a database that's accessed via the filename. If the filename string isn't exactly the same... then you can see what can be annoying about that.

    Is there any built in string function that can convert them?


    Jeremy

  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 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

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