|
-
Sep 8th, 2000, 09:10 PM
#1
Thread Starter
Addicted Member
Anyone know of a way to convert a shortened filename
into its corresponding long file name?
Example:
Convert: C:\MYDOCU~1\JUNKST~1\LONGFI~1.TXT
To: C:\My Documents\Junk Stuff\Long File Name Here.txt
-
Sep 9th, 2000, 08:40 PM
#2
Thread Starter
Addicted Member
-
Sep 9th, 2000, 09:14 PM
#3
Addicted Member
I dont think that is possible..
But if you find, please notify me
at:
[email protected]
-
Sep 9th, 2000, 09:27 PM
#4
Here is how to get the long or short filename:
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
-
Sep 11th, 2000, 09:45 AM
#5
Thread Starter
Addicted Member
OK ... Here we go.
Thanks everyone. I talked to Matthew about the code he provided. I couldn't get it to work. My Kernel32.dll doesn't understand the call to GetLongPathName. But, Matthew's post directed me to the site "Planet Source Code"
which did contain another code snippet that does work.
Thanks Matthew.
JC.
Here is the code:
[code]
Private Function sLongName(sShortName As String) As String
'sShortName - 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.
Dim sTemp As String
Dim sNew As String
Dim iHasBS As Integer
Dim iBS As Integer
If Len(sShortName) = 0 Then Exit Function
sTemp = sShortName
If Right$(sTemp, 1) = "\" Then
sTemp = Left$(sTemp, Len(sTemp) - 1)
iHasBS = True
End If
On Error GoTo MSGLFNnofile
If InStr(sTemp, "\") Then
sNew = ""
Do While InStr(sTemp, "\")
If Len(sNew) Then
sNew = Dir$(sTemp, 54) & "\" & sNew
Else
sNew = Dir$(sTemp, 54)
If sNew = "" Then
sLongName = sShortName
Exit Function
End If
End If
On Error Resume Next
For iBS = Len(sTemp) To 1 Step -1
If ("\" = Mid$(sTemp, iBS, 1)) Then
'found it
Exit For
End If
Next iBS
sTemp = Left$(sTemp, iBS - 1)
Loop
sNew = sTemp & "\" & sNew
Else
sNew = Dir$(sTemp, 54)
End If
MSGLFNresume:
If iHasBS Then
sNew = sNew & "\"
End If
sLongName = sNew
Exit Function
MSGLFNnofile:
sNew = ""
Resume MSGLFNresume
End Function
[\code]
-
Sep 11th, 2000, 10:58 AM
#6
GetLongPathName is new to windows 2000.
I guess someone found out it could be usefull.
-
Oct 23rd, 2000, 11:53 AM
#7
New Member
short from long...
hej
how can i get that long to short thing working? i need it bad! 
thanks..
-
Oct 23rd, 2000, 01:22 PM
#8
Matthew Gates' code above should work to get the short path.
-
Oct 23rd, 2000, 02:55 PM
#9
Re: short from long...
Originally posted by matse
hej
how can i get that long to short thing working? i need it bad! 
thanks..
Yes, it's all there matse.
Using the code I gave above:
Code:
Msgbox GetShortFilename("C:\WINDOWS\Start Menu\Programs\StartUp\")
'returns C:\WINDOWS\STARTM~1\PROGRAMS\STARTUP\
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
|