Functions and Directives

Function GetUniqueFileName() Foundation

Creates a unique name for a file.

GetUniqueFileName( [<cPath>], [<cPrefix>] ) --> cFileName
A character string that specifies the directory in which the file will be created. If no directory is specified, the default directory for temporary files is used. The default directory for temporary files is defined in the 'TEMP' environment variable.
Specifies an arbitrary prefix string. This parameter is optional and defaults to the character string 'xpp'.

GetUniqueFileName() returns a file name that is unique within the directory specified. The file name is returned including path information.


The function GetUniqueFileName() creates a unique file name. It can be used for creating temporary files using the low-level file functions, for example. The file name returned is comprised of a prefix (3 characters) and a number in hexadecimal format. The exact format of the file name returned is platform-dependent. Generally, it conforms to the following convention:


To ensure uniqueness of the filename the function creates an empty file <cFileName>. After the function returned an empty file with the corresponding name was created on the drive.

Example for using GetUniqueFileName()
// The example uses GetUniqueFileName() to create 
// a temporary file 

 LOCAL cFileName 
 LOCAL nFile 
 LOCAL cData := "Test data for temporary file" 

   cFileName := GetUniqueFileName( , "TST" )  // Sample return: "C:\TEMP\TST94.TMP" 
   nFile     := FCreate( cFileName ) 
   IF nFile == -1 
      Alert( "Can't create temporary file!" ) 

   FWrite( cData, Len(cData) ) 
   FClose( nFile ) 

   WAIT "Temporary file " + cFileName + " created. Please press a key." 


If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.