HB_FTempCreateEx
Creates and opens a temporary file.
Syntax
HB_FTempCreateEx( @<cFileName,;
<cTempDir>,;
<cPrefix>,;
<cFileExtension> --> <nFileHandle>
Arguments
@<cFileName> :must be passed by reference. It receives the file name of the created temporary file as a character string.
<cTempDir> : A character string specifying the directory where to create the temporary file. It defaults to the operating system variable SET TEMP or SET TMP. Operating system variables can be queried with function HB_GetEnv().
<cPrefix> : A character string of three characters specifying the prefix to use for the name of the temporary file. It defaults to the string “hb”.
<nFileExtension> : A character value specifying extension of the temporary file.
Returns
<nFileHandle> : a numeric value > 0 when the temporary file is successfully created. This is the file handle of the created temporary file.
Description
Function HB_FTempCreateEx() creates a temporary file and opens it. The return value is the file handle of the temporary file. It can be used with low level file functions, such as FWrite() to store data in the file. Temporary files are often required in an application.
HB_FTempCreateEx() guarantees that the file name of the newly created file is unique, so that no existing file will be overwritten. To obtain the file name of the temporary file, parameter <cFileName> must be passed by reference. It can then later be passed to function FErase() in order to remove the temporary file from disk.
HB_FTempCreateEx() is similar to HB_FTempCreate(), but allows to control the extension. Note, that the ordering of parameters had slightly changed compared to hb_fsCreateTemp().
Example
PROC TestHBFTempEx()
LOCAL nFileHandle
LOCAL cFileName
nFileHandle := HB_FTempCreateEx( @cFileName,; // File Name
,; // <cTempDir>
,; // <cPrefix>
'.tmp' ) // file extension
IF nFileHandle > 0
? 'Temp file builded with name :', cFileName
WAIT
FClose( nFileHandle )
FErase( cFileName )
ELSE
ALERT( "Couldn't build temp file" )
ENDI
RETU // TestHBFTempEx()
Seealso
TempFile(), HB_FTempCreate(), FCreate(), FErase(), FWrite(), HB_GetEnv()