unit Custom.Types;
interface
type
TFilePath =
type string;
TFilePathHelper =
record helper
for TFilePath
function Expand : TFilePath;
function Exists( FollowLink : Boolean = True ) : Boolean;
function GetDirectoryName :
string;
function GetFileName :
string;
function GetFileNameWithoutExtension :
string;
function GetFileExtension :
string;
function ForceDirectories : Boolean;
end;
implementation
uses
System.SysUtils,
Winapi.Windows,
System.IOUtils;
{ TFilePathHelper }
function TFilePathHelper.GetDirectoryName :
string;
begin
Result := TPath.GetDirectoryName( Self.Expand );
end;
function TFilePathHelper.GetFileExtension :
string;
begin
Result := TPath.GetExtension( Self.Expand );
end;
function TFilePathHelper.GetFileName :
string;
begin
Result := TPath.GetFileName( Self.Expand );
end;
function TFilePathHelper.GetFileNameWithoutExtension :
string;
begin
Result := TPath.GetFileNameWithoutExtension( Self.Expand );
end;
function TFilePathHelper.Exists( FollowLink : Boolean = True ) : Boolean;
begin
Result := TFile.Exists( Self.Expand, FollowLink );
end;
function TFilePathHelper.Expand : TFilePath;
var
LSize : Cardinal;
begin
SetLength( Result, MAX_PATH + 1 );
LSize := ExpandEnvironmentStrings( PChar( Self ), PChar( Result ), Length( Result ) );
SetLength( Result, LSize - 1 );
end;
function TFilePathHelper.ForceDirectories : Boolean;
begin
Result := System.SysUtils.ForceDirectories( Self.GetDirectoryName );
end;
end.