I suggest you ...

Some additional IOUtils goodies

Thanks Malcolm for implementing almost all of my recommendations. Maybe just a considence but I managed to deprecate almost all of my unt_Path, unt_Directory, unt_File methods.

What I still miss is:

class function TDirectory.IsReservedName(DirectoryName: string): Boolean;
begin
DirectoryName := LowerCase(DirectoryName);
if (DirectoryName = 'con') or
(DirectoryName = 'aux') or
(DirectoryName = 'prn') or
(DirectoryName = 'nul') or
(DirectoryName = 'lpt0') or
(DirectoryName = 'lpt1') or
(DirectoryName = 'lpt2') or
(DirectoryName = 'lpt3') or
(DirectoryName = 'lpt4') or
(DirectoryName = 'lpt5') or
(DirectoryName = 'lpt6') or
(DirectoryName = 'lpt7') or
(DirectoryName = 'lpt8') or
(DirectoryName = 'lpt9') or
(DirectoryName = 'com0') or
(DirectoryName = 'com1') or
(DirectoryName = 'com2') or
(DirectoryName = 'com3') or
(DirectoryName = 'com4') or
(DirectoryName = 'com5') or
(DirectoryName = 'com6') or
(DirectoryName = 'com7') or
(DirectoryName = 'com8') or
(DirectoryName = 'com9') then
Result := True
else
Result := False;
end;

2. class function GetTempFileName(const Prefix: string = 'tmp'): TFileName; static;
GetTempFileName to have a Prefix parameter

3. Add "Safety Belt" file name creation
/// <summary>
/// Returns file name which is valid. If invalid characters are supplied in the fileName
/// parameter they are removed
/// </summary>
// Url : http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=464878&SiteID=1
class function SafeFileName(const FileTitle: string): string; static;

4. Minimize Name

class function TPath.MinimizeName(Wnd: HWND; const Filename: string): string;
{ func to shorten the long path name with an ellipses '...' to fit }
{ in whatever control is passed to the Wnd parameter. }
{ Usage: Panel1.Caption := MinimizePathName(Panel1.Handle, DirectoryOutline1.Directory) }
{ This will shorten the path if necessary to fit in Panel1. }
procedure CutFirstDirectory(var S: string);
var
Root: Boolean;
P: Integer;
begin
if S = '\' then
S := ''
else
begin
if S[1] = '\' then
begin
Root := True;
Delete(S, 1, 1);
end
else
Root := False;
if S[1] = '.' then
Delete(S, 1, 4);
P := Pos('\',S);
if P <> 0 then
begin
Delete(S, 1, P);
S := '...\' + S;
end
else
S := '';
if Root then
S := '\' + S;
end;
end;

function GetTextWidth(DC: HDC; const Text: String): Integer;
var
Extent: TSize;
begin
if GetTextExtentPoint(DC, PWideChar(Text), Length(Text), Extent) then
Result := Extent.cX
else
Result := 0;
end;

var
Drive,
Dir,
Name: string;
R: TRect;
DC: HDC;
MaxLen: integer;
OldFont, Font: HFONT;
begin
Result := FileName;

if Wnd = 0 then
Exit;

DC := GetDC(Wnd);
if DC = 0 then
Exit;

Font := HFONT(SendMessage(Wnd, WM_GETFONT, 0, 0));
OldFont := SelectObject(DC, Font);
try
GetWindowRect(Wnd, R);
MaxLen := R.Right - R.Left;

Dir := ExtractFilePath(Result);
Name := ExtractFileName(Result);

if (Length(Dir) >= 2) and (Dir[2] = ':') then
begin
Drive := Copy(Dir, 1, 2);
Delete(Dir, 1, 2);
end
else
Drive := '';

while ((Dir <> '') or (Drive <> '')) and (GetTextWidth(DC, Result) > MaxLen) do
begin
if Dir = '\...\' then
begin
Drive := '';
Dir := '...\';
end
else
if Dir = '' then
Drive := ''
else
CutFirstDirectory(Dir);
Result := Drive + Dir + Name;
end;
finally
SelectObject(DC, OldFont);
ReleaseDC(Wnd, DC);
end;
end;

3 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    Gad D Lord shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    0 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      Signed in as (Sign out)
      Submitting...

      Feedback and Knowledge Base