Solved

Shortened pathname with \...\

Posted on 1998-09-03
6
480 Views
Last Modified: 2010-08-05
How do I shorten pathnames to fit a certain length space using an ellipsis (...) between backslashes?
0
Comment
Question by:rclay
6 Comments
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
How about something similar to this.,.....

var
  Path : string;
procedure TForm1.Button1Click(Sender: TObject);
begin
  if Length(path) > 10 then
    Path := Copy(path, 1, 10) + '\...\';
  Caption := Path;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
  Path := 'C:\windows\desktop\Viktor\Delphi';
  Caption := Path;
end;

Hope it helps! There are other ways to do that with the API, but it's not exactly what you are looking for     it does like this  C:\windows\desktop\vik...  and not C:\windows\desktop\vik\...\...\and so on.....

Regards,
Viktor Ivanov
0
 
LVL 7

Expert Comment

by:BlackMan
Comment Utility
If you want to do it the "Windows Way", let me know and I'll show you how to do it..
0
 

Author Comment

by:rclay
Comment Utility
Viktornet: What I'm looking for is a function or procedure that shortens the path by omitting its middle part, substituting an ellipsis. But it would break the pathname at a '\', not at some arbitrary point such as at the 10th character. Also the total length of the resulting pathname should be adjustable at design- or run-time by the programmer.

Blackman: Yes, I would like to know how to do it the windows way.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 5

Expert Comment

by:JimBob091197
Comment Utility
Hi

The DrawTextEx API function will fill in the ellipsis for you.  You give the function a string (PChar), a rectangle and a canvas, and if the text doesn't fit into the rectangle then it uses ellipsis.

E.g.
DrawTextEx(Canvas.Handle, PChar(SomeStr), Length(SomeStr), SomeRect, DT_PATH_ELLIPSIS or DT_MODIFYSTRING, nil);

Unfortunately you don't get the result string (with ellipsis) back.

JB
0
 
LVL 7

Accepted Solution

by:
BlackMan earned 100 total points
Comment Utility
Here's an example (taken from a "live" application). It takes the value of AString and shorten it so that it fits in Label1.

Var
  AString: String;
  r: TRect;
begin
  AString := '\\MyServer\MyShare\ThisDirectory\ThatDirectory\MyFile';
  r.Left := 0;
  r.Right := Label1.Width;
  r.Top := 0;
  r.Bottom := Label1.Height;
  Windows.DrawText(Label1.Canvas.Handle, @AString[1], Length(AString), r, DT_Left or DT_PATH_ELLIPSIS or DT_MODIFYSTRING or DT_CALCRECT );
  Label1.caption := AString;
End;
0
 

Author Comment

by:rclay
Comment Utility
Thanks for the input Viktornet, JimBob, and BlackMan!
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 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

16 Experts available now in Live!

Get 1:1 Help Now