Quantcast
Channel: VBForums - API
Viewing all articles
Browse latest Browse all 168

Convert 8.3 Short filenames to long filenames

$
0
0
I have many short filenames that I wish to convert to a long filename in the Plus! theme directory.

Example: SPORTS~4.WAV

Using GetLongPathName is returning the exact filename and case in the specified buffer.

When I think I should be expecting something like 'Sports Startup.wav' returned.

Heres the code,


Option Explicit

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

Private Declare Function LoadLibrary Lib "kernel32" _
Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long

Private Declare Function GetProcAddress Lib "kernel32" _
(ByVal hModule As Long, ByVal lpProcName As String) As Long

Private Declare Function FreeLibrary Lib "kernel32" _
(ByVal hLibModule As Long) As Long

Const MAX_PATH = 260


Public Function GetLongFileName(ByVal FullPath As String) _
As String

'*****************************************
'USAGE: Convert short (8.3) file name to long file name
'INPUT: FULL PATH OF A SHORT FILE NAME
'RETURNS: LONG FILE NAME:
'EXAMPLE: dim sLongFile as String
' sLongFile = GetLongFileName("C\:MyShor~1.txt")
'NOTES: ONLY WORKS ON WIN 98 and WIN 2000. WILL RETURN
' EMPTY STRING ELSEWHERE
'***********************************************************

Dim lLen As Long
Dim sBuffer As String

'Function only available on '98 and 2000,
'so we check to see if it's available before proceeding

If Not APIFunctionPresent("GetLongPathNameA", "kernel32") _
Then Exit Function

sBuffer = String$(MAX_PATH, 0)
lLen = GetLongPathName(FullPath, sBuffer, Len(sBuffer))
If lLen > 0 And Err.Number = 0 Then
GetLongFileName = Left$(sBuffer, lLen)
End If
End Function

Private Function APIFunctionPresent(ByVal FunctionName _
As String, ByVal DllName As String) As Boolean

'http://www.freevbcode.com/ShowCode.Asp?ID=429

Dim lHandle As Long
Dim lAddr As Long

lHandle = LoadLibrary(DllName)
If lHandle <> 0 Then
lAddr = GetProcAddress(lHandle, FunctionName)
FreeLibrary lHandle
End If

APIFunctionPresent = (lAddr <> 0)

End Function

Viewing all articles
Browse latest Browse all 168

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>