TempFileName Function

Purpose

Creates a name for a temporary file.

Syntax

file$ = TempFileName(prefix$ [, extension$])

Description

TempFileName tries to create a temporary file in the user's %TEMP% directory and returns the name in file$ - if file$ is empty (""), then the operation failed.

The TempFileName function is a shortcut for the GetTempFileName API function which will only create the temporary file if it has a unique filename. Through the API, GFA Basic creates a temporary filename which is a concatenation of a prefix string (if prefix$ <> ""), a hexadecimal string derived from the current system time, and a specified extension (or .tmp if none is supplied in extension$).

The prefix$ argument may be left empty ("") so that the filename part is entirely made up of a unique hexadecimal value.

Example

Trace TempFileName("")

Trace TempFileName("~", "dat")

Trace TempFileName("gfa")

Global Handle hCur = InlLoadCursor("C:\Windows\Cursors\aero_busy.ani")

 

Function InlLoadCursor(fname$) As Handle

Dim path$ = TempFileName("gfa")

Trace fname$ : Trace path$

CopyFile fname$ Over To path$

InlLoadCursor = LoadCursorFromFile(path$)

KillTempFile path$

EndFunc

Remarks

File systems attempt to keep all of the data in memory for quicker access rather than flushing the data back to mass storage. A temporary file should be deleted by the application as soon as it is no longer needed.

A file created with the TempFileName function is automatically deleted when the programs exits. KillTempFile is used when a temporary file is to be deleted explicitly.

See Also

KillTempFile, LoadBmp

{Created by Sjouke Hamstra; Last updated: 06/06/2021 by James Gaite}