Creating abbreviated path name

Posted on 2006-05-08
Last Modified: 2008-02-01
I'm sure I saw, somewhere, a method to shrink down the size of a path when it's too long to fit in the space available. So instead of


it might be


But I can't for the life of me remember what it was called, or what namespace to look in. I believe the same method had alternates which would abbreviate a string in other ways (cut off the left side, cut off the right side, etc.) Can anyone point me in the right direction?
Question by:ElrondCT
    LVL 19

    Expert Comment

    I am not sure if there's any function to get the short path the way you actually want it.
    I mean the C:\firstlevel\...\   i.e the "..." stuff. Though you can write a small code for that.

    The usual way is having the Short Path as the Command Prompt shows it. Eg.
    i.e the "~" and 1, 2 etc.

    In case you want to use this standard format use the API "GetShortPathName"
    Here's how

    Public Declare Function GetShortPathName Lib "kernel32" Alias GetShortPathNameA _
       (ByVal lpszLongPath As String, ByVal lpszShortPath _
       As String, ByVal cchBuffer As Long) As Long

    Then to call this API

    Dim LongPath As String="c:\SomeLongFolder\AnotherNestedFolder\YourFile.txt"
    Dim ShortPath As String
    Dim Ln as integer
    Ln=LongPath.Length +1
    ShortPath=New String(" ",Ln)
    GetShortPathName (LongPath, ShortPath, Ln)
    MsgBox ShortPath

    LVL 8

    Accepted Solution

    check out this tutorial

    is really good an explains loads of different options for displaying
    LVL 8

    Expert Comment

    btw, is vb6 code but should be easy to convert. just ask if u need help doin it an one of us will oblige :)
    LVL 20

    Author Comment

    Using the 8-character folder/filenames is not what I had in mind, arif_eqbal, as even those could end up being too long if there are several levels of subfolders; that could, however, be useful in other circumstances. What I was looking for was the PathCompactPath function that's described in the link rfgkev shows, though that particular tutorial isn't, IMHO, the easiest way to use the function. But with the right name, it's easy enough to look up other information online. I wasn't thinking about Windows APIs when I was looking for this, which is part of the reason I couldn't find it. Thanks for the pointer!
    LVL 85

    Expert Comment

    by:Mike Tomlinson

    Did you find the VB.Net equivalent?

    You use the EllipsisPath flag with the Graphics.DrawString() function:

    LVL 20

    Author Comment

    Idle_Mind, that was exactly what I was thinking of. Thank you.

    I'd add points to give to you, but I don't know a way to do that once another answer has been accepted...
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    Don't worry about the points...  =)

    I would have answered yesterday but I went to bed really early as I haven't been feeling well lately due to having my wisdom teeth pulled out.   =O

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    Introduction When many people think of the WebBrowser ( control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now