dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
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 10, 2001

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


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, "\")
Loop
' Prefix with the drive letter
GetLongFilename = Left$(sShortName, 2) & sLongName
End Function
'From any place, add this line
GetLongFilename("C:\PROGRA~1\COMMON~1")

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.

 

 

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