Scalabium Software

SMExport/SMImport suites
Knowledge for your independence'.
Home Delphi and C++Builder tips


#100: How can I retrieve a temporary path from MS Windows?

I thought that I posted the tip about Windows temporary path and temporary files but today I found that didn't post it...

In development the most popular task is to create a some temporary file with some info and in finalization of application to remove this file. Of course, you can create this file in folder with your application but it's bad style. For example, imagine that your application was freeze or user restarted a Windows when your application was active. It's not a good when in folder with your application you'll create a trash with some "dead" files...

For this task you must use the TEMP folder. But problem in the next - in each Windows version this folder is different. Also the user can redefine the folder location. So you must read the some "system" function which will return you a value with active temp.path.

This "system" function is GetTempPath from Windows API. View a small example:

var
  TempPath, TempFileName: array[0..MAX_PATH] of Char;
  FileName: string;
begin
    {read the temporary path}
    GetTempPath(MAX_PATH, @TempPath);

    {for example, create a temp.file in this folder
    The GetTempFileName will generate the temp.file name with 'tmp'-prefix}
    GetTempFileName(@TempPath, 'tmp', 0, @TempFileName);
    {change the extension to .bmp}
    FileName := ChangeFileExt(StrPas(@TempFileName), '.bmp');

    {save the some bitmap in this created file}
    bmp.SaveToFile(FileName);

<here you can place a code for actions with this file>

  {don't forget to remove a temporary file}
  DeleteFile(FileName);
end;


Published: October 10, 2000

See also
 
Paradox Password Recovery
ABA Database Convert
Paradox ActiveX
dBase Viewer
Database Information Manager
Fast Document Viewer
Mail parser (ActiveX)
Word Web-stream
Paradox to MS Access converter
Protected Storage Viewer
 
 


Contact to webmaster

 

Borland Software Code Gear Scalabium Delphi tips

Copyright© 1998-2025, Scalabium Software. All rights reserved.
webmaster@scalabium.com

SMExport advertising