Scalabium Software

SMExport advertising
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
 
DBISAM Password Recovery
Viewer for MS Outlook Messages
Mail parser (ActiveX)
Paradox to MS Access converter
Metafile Convert
DBISAM Viewer
Word Web-stream
Paradox ActiveX
Excel Reader (dll)
dBase Viewer
 
 


Contact to webmaster

 

Borland Software Code Gear Scalabium Delphi tips

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

SMExport advertising