Api function to convert Long File Names To Short Dos File Names 
Author Message
 Api function to convert Long File Names To Short Dos File Names

Greetings,

My VB5.0 APP is receiving a list of files to process via drag-and drop from
explorer.
My VB app must then call a legacy DOS program to filter these files.
the DOS app does not understand long file names.  Is there a function or
API call that will perform the conversion?

I know I can take the first 6 char and append ~1, but this will not work
100% of
the time. (The case of files with the same name beyond the 8.3 format.

Any ideas would be appreciated.
Brian



Sat, 15 Jul 2000 03:00:00 GMT  
 Api function to convert Long File Names To Short Dos File Names

Dear Brian,

here is a piece of code I wrote some time ago, please feel free to use it

Syntax: <shortfilename> = MakeDOSName(<longfilename>)

Private Const MAX_PATH As Integer = 260

Private Declare Function GetShortPathName Lib "kernel32" Alias
"GetShortPathNameA" _
                (ByVal lpszLongPath As String, _
                 ByVal lpszShortPath As String, _
                 ByVal cchBuffer As Long) As Long

Private Function MakeDOSName(ByVal szLongFileName As String) As String
    Dim lAPIResult As Long

    ' Initialize string w/empty spaces
    MakeDOSName = Space$(MAX_PATH)

    ' Call WinAPI
    lAPIResult = GetShortPathName(szLongFileName, _
                                  MakeDOSName, _
                                  Len(MakeDOSName))

    If (lAPIResult) Then
        ' we need to strip the string delimiter
        MakeDOSName = Mid$(MakeDOSName, 1, lAPIResult)
    End If

    ' All set
    MakeDOSName = Trim$(MakeDOSName)
End Function

Hope this helps,
Luca G. Fontanarosa
Sr. Software Engineer



Sun, 16 Jul 2000 03:00:00 GMT  
 Api function to convert Long File Names To Short Dos File Names

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

Public Function ShortFileName(ByVal LongFileName As String) As String
' Purpose:     Changes long filenames to it's equivalent short filename (in 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
   Dim Buffer$
   Dim Result&

   LongFileName = Trim$(LongFileName)
   On Error Resume Next
   If Len(LongFileName) Then
      Buffer$ = Space$(128)
      Result& = OSGetShortPathName&(LongFileName, Buffer$, Len(Buffer$))
      ShortFileName = IIf(Result& > 0, Left$(Buffer$, Result&), LongFileName$)
   End If
   On Error GoTo 0
End Function

Paul Schirf



Mon, 17 Jul 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Converting Long File Names to Short File Names

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

3. Convert Long Folder Names to DOS Short Dir Names

4. Get long file name from short file name

5. Long File Names and Short File Names

6. Get Short File Name from Long File Name?

7. Long file names to short file name

8. Getting short file name from long file name:

9. long file names to short file name

10. Long File Names and Short File Names

11. Short File Name to Long File Name

12. How can i truncate long file name to get dos file name

 

 
Powered by phpBB® Forum Software