|
-
Nov 13th, 2000, 08:44 PM
#1
Thread Starter
Frenzied Member
Hi,
I need to change a short filename
to a long file name, how do I do
that?
Thanks!
-
Nov 13th, 2000, 08:46 PM
#2
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
-
Nov 13th, 2000, 10:04 PM
#3
Addicted Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|