View Single Post
  #1  
Old 12-18-2006, 07:32 AM
kate kate is offline
Senior Member
 
Join Date: Feb 2001
Posts: 356
Default Best way to get Windows Temp Directory

Hi,
I got two code snippet for getting windows temp directory. I just want your expert comment as to which one will work best and why. If there is a better one, do please quote. Should apply to both Administrator and non-administrator login on all windows version. Thank you for your assistance:

1.
function GetTempDirectory: String;
var
tempFolder: array[0..MAX_PATH] of Char;
begin
GetTempPath(MAX_PATH, @tempFolder);
result := StrPas(tempFolder);
end;

{================================================= =======}

2.
function WindowsTemp : String;
var
Buffer : Array[0..Max_path] of char;
begin
FillChar(Buffer,Max_Path + 1, 0);
GetTempPath(Max_path, Buffer);
Result := String(Buffer);
if Result[Length(Result)] <> '\' then Result := Result + '\';
end;
Reply With Quote