RxFPC: new function - RxGetTempFileName

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6735 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
alexs75
2018-11-23 10:52:49 +00:00
parent 3c32ab66fa
commit 9940c604cc
3 changed files with 41 additions and 1 deletions

View File

@ -45,7 +45,7 @@ function GetUserName:string;
function IsValidFileNameChar(const AChar: Char): Boolean;inline;
function NormalizeFileName(const FileName:string; AReplaceChar:char = '_'):string; //funtion only for filename - without folder name
function RxGetTempFileName(ADir, APrefix, AExt : string):string;
const
{$IFDEF WINDOWS}
FileNameDisabledChars = [#0 .. #31, '"', '*', '/', ':', '<', '>', '?', '\' , '|'];
@ -243,5 +243,39 @@ begin
Result[i]:=AReplaceChar;
end;
function RxGetTempFileName(ADir, APrefix, AExt: string): string;
var
Start: String;
i: Integer;
begin
if AExt = '' then
begin
AExt:=ExtractFileExt(APrefix);
if AExt<>'' then
begin
APrefix:=ExtractFileName(APrefix);
end
else
AExt:='.tmp';
end;
if (APrefix = '') then
Start:='TMP'
else
Start:=APrefix;
if (ADir='') then
Start:=GetTempDir + Start
else
Start:=IncludeTrailingPathDelimiter(ADir) + Start;
i:=0;
repeat
Result:=Format('%s%.5d%s',[Start, I , AExt]);
Inc(I);
until not FileExists(Result);
end;
end.