lang • temp

Temp$

File name = Temp$( [ Prefix ] ) File name = Temp( [ Prefix ] )

Return a path for a temporary file.

The path has the following form:

/tmp/gambas.<UserId>/<ProcessId>/<Prefix>.tmp

where:

  • <UserId> is the user system identifier.

  • <ProcessId> is the system identifier of the current process.

  • <Prefix> is the value of the Prefix string argument.

If Prefix is not specified, then it is replaced by an integer number incremented each time this function is called. This way, the returned file name is always unique.

This function only returns a path. You can use this path to create a file, a directory, socket, symlink or whatever.

    Dim sDir As String = Temp$()
    
    ' Extract an archive to a temporary directory first
    Mkdir sDir
    Exec ["tar" "-zxf", "archive.tar.gz", "-C", sDir] Wait
    
    ' If unsuccessful, no need to clean up
    If Process.LastValue Then Return ErrorCode
    ...

All files located in the /tmp/gambas.<UserId>/<ProcessId> directory are automatically removed when the Gambas program ends.

Examples

Print Temp$()
/tmp/gambas.501/14593/1.tmp
Print Temp$()
/tmp/gambas.501/14593/2.tmp
Print Temp$("version")
/tmp/gambas.501/14593/version.tmp

See also