Delphi Pages Forums

Delphi Pages Forums (http://www.delphipages.com/forum/index.php)
-   General (http://www.delphipages.com/forum/forumdisplay.php?f=2)
-   -   Best way to get Windows Temp Directory (http://www.delphipages.com/forum/showthread.php?t=176698)

kate 12-18-2006 07:32 AM

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;

Jasser 12-18-2006 08:28 AM

RE: Best way to get Windows Temp Directory
 
This is the best one. It's easy, short, and effective.

[DELPHI]Showmessage( GetEnvironmentVariable('TEMP') );[/DELPHI]

Regards,
Abdulaziz Jasser

Norrit 12-18-2006 11:03 PM

RE: Best way to get Windows Temp Directory
 
And I always use this one:
Code:

function TempFolder: String;
var
  bufFolder: array [0..MAX_PATH] of Char;
begin
  GetTempPath(SizeOf(bufFolder), bufFolder);
  Result := IncludeTrailingPathDelimiter(String(bufFolder));
end;

So you see, it's all a matter of personal flavor...
Only one I wouldn't use is the GetEnvironmentVar, because it goes directly to environment variables... This depends on a variable that I can modify by hand... The GetTempPath method is windows API, so I choose this one...

Objective reality is a delirium caused by lack of alcohol in blood.
There is no place like 127.0.0.1

hemaulo 12-18-2006 11:21 PM

RE: Best way to get Windows Temp Directory
 
Why do you want to get system's temp dir? Create one named temp in your application's folder and use it. After closing application you can empty it.

Medniex

Norrit 12-19-2006 12:30 AM

RE: Best way to get Windows Temp Directory
 
NOTE:
Not all end-users have full-rights on their system... Using the windows temp is always safer then your solution (own temp-folder)...

Objective reality is a delirium caused by lack of alcohol in blood.
There is no place like 127.0.0.1

jjsanes 01-29-2018 03:11 PM

Quote:

Originally Posted by hemaulo (Post 176723)
Why do you want to get system's temp dir? Create one named temp in your application's folder and use it. After closing application you can empty it.

Medniex

Not a bad idea. The problem is, this would work only if the application is not running from a Read-only unit (CD-DVD).:(


All times are GMT. The time now is 09:50 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.