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:

  TempPath, TempFileName: array[0..MAX_PATH] of Char;
  FileName: string;
    {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}

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

  {don't forget to remove a temporary file}

Published: October 10, 2000

See also
Mail parser (ActiveX)
Excel Reader (dll)
SMExport suite
DBISAM Password Recovery
ABA Database Convert
ABA Document Convert
Viewer for TNEF-files (winmail.dat)
ExcelFile Viewer
Viewer for MS Outlook Messages

Contact to webmaster


Borland Software Code Gear Scalabium Delphi tips

Copyright© 1998-2024, Scalabium Software. All rights reserved.

SMExport advertising