Solved

Getting Windows Temp Directory

Posted on 1998-09-14
4
183 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

691 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