Function GetUniqueFileName() Foundation

Creates a unique name for a file.

Syntax
GetUniqueFileName( [<cPath>], [<cPrefix>] ) --> cFileName
Parameters
<cPath>
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.
<cPrefix>
Specifies an arbitrary prefix string. This parameter is optional and defaults to the character string 'xpp'.
Return

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

Description

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:

"<cPath>\<cPrefix><number>.TMP" 

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.

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

 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!" ) 
      QUIT 
   ENDIF 

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

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

RETURN 
Feedback

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.