Expand/Shrink

temp_file

Definition: string filename = temp_file(string location="", prefix="", extn="tmp", open_mode="")
--or--
{integer fn, string filename} = temp_file( ditto ) -- (if open_mode!="")
Description: Create a temporary filename, which does not already exist, and optionally open it.

location: The directory where the file should be created. If omitted it uses %TEMP% or %TMP%, or C:\temp\ or /tmp/.
prefix: the (optional) first part of the filename.
extn: the file extension to use, default is "tmp".
open_mode: if not "", must be one of "w", "wb", "a", or "ab", in which case it returns an open file handle and string.

If open_mode is not provided, there is a 1-in-a-million chance someone else will beat you to the punch; if you do provide one, it will open/loop for you, and return {fn,filename}. In the latter case you are expected to close and delete the file.
pwa/p2js: Not supported.
Example:
pp(temp_file())
{integer fn, string name} = temp_file("myapp/tmp","data","log","wb")
pp({fn,name})
close(fn)
{} = delete_file(name)
-- output:
-- `C:\Users\Pete\AppData\Local\Temp\419750.tmp`
-- {3, `C:\Program Files (x86)\Phix\myapp\tmp\data408865.log`}
See Also: open, close, delete_file
Implementation: See builtins\pfile.e (an autoinclude) for details of the actual implementation.
Expand/Shrink