Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #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
  #2  
Old 12-18-2006, 08:28 AM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,059
Default 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
Reply With Quote
  #3  
Old 12-18-2006, 11:03 PM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,307
Default 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
Reply With Quote
  #4  
Old 12-18-2006, 11:21 PM
hemaulo hemaulo is offline
Senior Member
 
Join Date: Dec 2003
Posts: 285
Default 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
Reply With Quote
  #5  
Old 12-19-2006, 12:30 AM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,307
Default 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
Reply With Quote
  #6  
Old 01-29-2018, 03:11 PM
jjsanes jjsanes is offline
Junior Member
 
Join Date: Jan 2018
Posts: 1
Exclamation

Quote:
Originally Posted by hemaulo View Post
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).
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 11:11 PM.


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