VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Converting long file names

by VB Pro (6 Submissions)
Category: Files/File Controls/Input/Output
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (39 Votes)

VB4's commands for dealing with file names (such as KILL, MKDIR, and FILECOPY) support long file names without programmer interaction. A number of the Win95 API functions will return only the short name, and you'll notice a number of short file name entries if you're digging through the registration database. Therefore, occasionally you'll need to convert a short file name into a long file name.
This function lets you pass a long file name with no ill effects. The file must exist for the conversion to succeed. Because this routine uses Dir$ and "walks" the path name to do its work, it will not impress you with its speed:

Rate Converting long file names

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

Download this snippet    Add to My Saved Code

Converting long file names Comments

No comments have been posted about Converting long file names. Why not be the first to post a comment about Converting long file names.

Post your comment

Subject:
Message:
0/1000 characters