Skip Navigation Links.
Getting a temporary filename from Windows
Language(s):I-Series - CLP
Category(s):Include Files

It is often necessary to create a file with a unique file name. This example shows how to use the Windows API to do this.

  This sample code is presented as is.
  Although every reasonable effort has been
  made to insure the soundness of the example
  below, Idioma Software inc. makes no warranty
  of any kind with regard to this program sample
  either implicitly or explicitly.

  This program example may be freely distributed for the
  use of writing computer programs only. Any other use of
  this material requires written permission from Idioma Software inc.

  (c) 1997 Idioma Software inc. All rights reserved.

 This example shows how to get a temporary file name
function TempFileName : String;
{Author Jon Vote 10/97}

const Unique : word = 0;

var DriveLetter : char;
    pTempFileName : pchar;
    dummy         : word;
    Prefix : pChar;

 Prefix := 'TMP';
 pTempFileName := StrAlloc(256);
 DriveLetter := GetTempDrive(' ');
 {convert 'A' to '1', ... 'C' to '3' - etc}
 DriveLetter := chr(ord(DriveLetter) - 18);
 dummy := GetTempFileName(DriveLetter, PreFix, Unique, pTempFileName);
 ShowMessage('Temp filename is: ' + strpas(pTempFileName));
 TempFileName := strpas(pTempFileName);

This article has been viewed 2133 times.
The examples on this page are presented "as is". They may be used in code as long as credit is given to the original author. Contents of this page may not be reproduced or published in any other manner what so ever without written permission from Idioma Software Inc.