Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

GetShortenedFileName - Make a filename shorter using ellipses

Total Hit ( 1888)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 



Click here to copy the following block
' return a file path not longer than the number of character
' specified in the 2nd argument
'
' If necessary, it replaces directory names with ellipsises
'
' Author: Fred Block
'     CuzWare Systems
'     E-mail: fblock@cuzware.com
'     Web Site: http://www.cuzware.com

Function GetShortenedFileName(ByVal strFilePath As String, _
  ByVal maxLength As Long) As String
  Dim astrTemp() As String
  Dim lngCount As Long
  Dim strTemp As String
  Dim index As Long
  
  ' if the path is shorter than the max allowed length, just return it
  If Len(strFilePath) <= maxLength Then
    GetShortenedFileName = strFilePath
  Else
    ' split the path in its constituent dirs
    astrTemp() = Split(strFilePath, "\")
    lngCount = UBound(astrTemp)
    
    ' lets replace each part with ellipsis, until the length is OK
    ' but never substitute drive and file name
    For index = 1 To lngCount - 1
      astrTemp(index) = "..."
      ' rebuild the result
      GetShortenedFileName = Join(astrTemp, "\")
      If Len(GetShortenedFileName) <= maxLength Then Exit For
    Next
  End If
  
End Function


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.