• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 365
  • Last Modified:

Creating abbreviated path name

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

C:\firstlevel\secondlevel\thirdlevel\fourthlevel\myfile.txt

it might be

C:\firstlevel\...\fourthlevel\myfile.txt

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?
0
ElrondCT
Asked:
ElrondCT
  • 2
  • 2
  • 2
  • +1
1 Solution
 
arif_eqbalCommented:
Hi
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.
c:\Progra~1\SomeFo~1\YourFile.txt
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


0
 
rfgkevCommented:
check out this tutorial

http://vbnet.mvps.org/index.html?code/fileapi/drawtextpath.htm

is really good an explains loads of different options for displaying
0
 
rfgkevCommented:
btw, is vb6 code but should be easy to convert. just ask if u need help doin it an one of us will oblige :)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ElrondCTAuthor Commented:
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!
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
ElrondCT,

Did you find the VB.Net equivalent?

You use the EllipsisPath flag with the Graphics.DrawString() function:
http://msdn2.microsoft.com/en-us/library/system.drawing.stringtrimming.aspx

~IM
0
 
ElrondCTAuthor Commented:
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...
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now