#1 2023-05-01 23:02:05

tbo
Member
Registered: 2015-04-20
Posts: 354

function MakeFileName request

Could a function like this be introduced:

function MakeFileName(const pmcPart: array of const; pmLastIsExt: Boolean): TFileName;
var
  ext: RawUtf8;
begin
  if pmLastIsExt
    and (Length(pmcPart) > 1)
    and VarRecToUtf8IsString(pmcPart[High(pmcPart)], ext) then
  begin
    Result := MakePath(Slice(pmcPart, Length(pmcPart) - 1));
    if (Result <> '')
      and (ext <> '') then
    begin
      if ext[1] = '.' then
        Result := Result + Utf8ToString(ext)
      else
        Result := Result + '.' + Utf8ToString(ext);
    end;
  end
  else
    Result := MakePath(pmcPart);
end;

Then you could write the following without looking at anything:

const
  PNG_EXT = 'png';
begin
  ShowMessage(MakeFileName([Executable.ProgramFilePath, 'One', 'TestFile', PNG_EXT], True));
  ShowMessage(MakeFileName(['C:', 'One', 'TestFile', ExtractFileExt(Executable.ProgramFileName)], True));

With best regards
Thomas

Offline

#2 2023-05-02 07:54:34

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,713
Website

Re: function MakeFileName request

Offline

Board footer

Powered by FluxBB