Solved

Getting Windows Temp Directory

Posted on 1998-09-14
4
173 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

911 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now