Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Visual Basic
Expertise: Beginner
Dec 11, 2001



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Convert a Short Filename Into a Long Filename

You can use the Dir( ) function to return a long filename, but the return does not include path information. By parsing a given short path/filename into its constituent directories, you can use the Dir( ) function to build a long path/filename with 32-bit versions of VB, without the assistance of APIs:
Public Function GetLongFilename(ByVal _
sShortName As String) As String
Dim sLongName As String
Dim sTemp As String
Dim iSlashPos As Integer
' Add \ to short name to prevent Instr from failing
sShortName = sShortName & "\"
' Start from 4 to ignore the "[Drive
' Letter]:\" characters
iSlashPos = InStr(4, sShortName, "\")
' Pull out each string between \ character for conversion
Do While iSlashPos
sTemp = Dir(Left$(sShortName, _
iSlashPos - 1), vbNormal Or vbHidden _
Or vbSystem Or vbDirectory)
If sTemp = "" Then
' Error 52 - Bad File Name or Number
GetLongFilename = ""
Exit Function
End If
sLongName = sLongName & "\" & sTemp
iSlashPos = InStr(iSlashPos + 1, sShortName, "\")
' Prefix with the drive letter
GetLongFilename = Left$(sShortName, 2) & sLongName
End Function
'From any place, add this line

This function, as written, expects a standard fully qualified, drive-based filespec.
Alex Leyfman
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date