Convert Long Folder Names to DOS Short Dir Names 
Author Message
 Convert Long Folder Names to DOS Short Dir Names

Quote:

>Can someone please send me the source code for converting a Long path to a
>short dos path.

Private Declare Function SKGetLongPathName Lib "VB5STKIT.DLL" _
                       Alias "GetLongPathName" _
                       (ByVal LongPath$, ByVal ShortPath$, _
                        ByVal BufferSize&) As Long

Private Declare Function OSGetShortPathName& Lib "kernel32" _
                       Alias "GetShortPathNameA" _
                       (ByVal lpszLongPath$, ByVal lpszShortPath$, _
                         ByVal cchBuffer&)

Public Function ShortFileName(ByVal LongFileName$) As String
'-----------------------------------------------------------------------
' Purpose:     Changes long filenames to it's equivalent short filename
'              (DOS 8.3 format)
' Arguments:   LongName (name of file)
' Returns:     Short filename
' Notes:       The file and directory must exist for this to work.
'              32-Bit function
'-----------------------------------------------------------------------
   Const BufferSize = 300
   Dim Buffer$
   Dim Result&

   On Error Resume Next
   LongFileName$ = Trim$(LongFileName$)
   If Len(LongFileName$) Then
      Buffer$ = String(BufferSize, Chr$(0))
      Result& = OSGetShortPathName&(LongFileName$, Buffer$, BufferSize)
      If Result& <> 0 Then
         ShortFileName = x_StripTerminator(Buffer$)
      End If
   End If
   On Error GoTo 0
End Function

Public Function LongFileName(ByVal ShortFileName$) As String
' Purpose:     Retrieve the long pathname version of a path possibly
'              containing short subdirectory and/or file names
' Arguments:   ShortFileName$ (name of file)
' Returns:     Long filename
' Notes:       The file and directory must exist for this to work.
'              32-Bit function
   Const BufferSize = 300
   Dim Buffer$
   Dim Result&

   On Error Resume Next
   ShortFileName$ = Trim$(ShortFileName$)
   If Len(ShortFileName$) Then
      Buffer$ = String(BufferSize, Chr$(0))
      Result& = SKGetLongPathName(ShortFileName$, Buffer$, BufferSize)
      If Result& <> 0 Then
         LongFileName = x_StripTerminator(Buffer$)
      End If
   End If
   On Error GoTo 0
End Function

Private Function x_StripTerminator(ByVal Expression As String) As String
' Returns a string without any zero terminator.  Typically,
' this was a string returned by a Windows API call.
'
' IN: [Expression] - String to remove terminator from
'
' Returns: The value of the string passed in minus any
'          terminating zero.

    Dim ZeroPos%

    ZeroPos% = InStr(Expression, Chr$(0))
    If ZeroPos% > 0 Then
        x_StripTerminator = Left$(Expression, ZeroPos% - 1)
    Else
        x_StripTerminator = Expression
    End If
End Function



Mon, 06 Nov 2000 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Api function to convert Long File Names To Short Dos File Names

2. Converting Long File Names to Short File Names

3. How to convert long file names to short file names

4. How to get short DOS 8.3 file names from long filenames

5. Get long file name from short file name

6. Long File Names and Short File Names

7. Get Short File Name from Long File Name?

8. Long file names to short file name

9. Getting short file name from long file name:

10. long file names to short file name

11. Long File Names and Short File Names

12. Short File Name to Long File Name

 

 
Powered by phpBB® Forum Software