Solved

Getting Windows Temp Directory

Posted on 1998-09-14
4
175 Views
Last Modified: 2010-04-06
I think I am overlooking something basic, but is there a easy way to get the current windows "temp" directory? This will need to work on W95, W98 and WinNT.
0
Comment
Question by:TonyMalo
4 Comments
 
LVL 10

Accepted Solution

by:
viktornet earned 50 total points
ID: 1339710
Here is the easiest way....

var
  Temp : array[0..100]of char;
begin
  GetTempPath(SizeOf(Temp), Temp);
  ShowMessage(StrPas(Temp));
end;

Regards,
Viktor Ivanov
0
 
LVL 4

Expert Comment

by:erajoj
ID: 1339711
Note:
Viktor, Tony, always set the upper boundary to MAX_PATH (144) when dealing with windows system paths.

var
  Temp: array[0..MAX_PATH] of Char;

/// John
0
 

Author Comment

by:TonyMalo
ID: 1339712
Tanks to all, I knew there was a simple answer
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1339713
One thing to watch:

result is:
1.The path specified by the TMP environment variable.
2.The path specified by the TEMP environment variable, if TMP is not defined.
3.The current directory, if both TMP and TEMP are not defined.

i've put some functions like the one you were looking for into a unit. this is what it looks like:

function strGet_SysDir: string;
begin
  p := StrAlloc(Succ(MAX_PATH));
  GetSystemDirectory(p, MAX_PATH);
  Result := StrPas(p);
  StrDispose(p);
end;

Black Death.
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question