TemporaryFile - Maple Help

FileTools

 TemporaryFilename
 return a filename that may be used for a temporary file
 TemporaryFile
 return a filepath that may be used for a temporary file

 Calling Sequence TemporaryFilename(prefix,suffix) TemporaryFile(prefix,suffix,opt)

Parameters

 prefix - (optional) string prefix for the temporary name suffix - (optional) string suffix for the temporary name opt - (optional) option of the form directory=s as described below

Options

 • directory=string or one of bindir, datadir, homedir, mapledir, tempdir, toolboxdir, worksheetdir.
 The directory option specifies the directory in which the temporary file should be generated. The default value, tempdir, indicates that the directory returned by FileTools[TemporaryDirectory] should be used.
 For the meaning of bindir, datadir, homedir, mapledir, or toolboxdir, see kernelopts. For the meaning of worksheetdir, see interface.

Description

 • The TemporaryFilename function returns a string that can be used as the name of a temporary file. The returned filename is of the form $\mathrm{MapleXXXXXX}$, where each $X$ is replaced with a random character.
 • The TemporaryFile function performs a similar task but uses a temporary directory as its default destination.
 • If the optional prefix is provided, then the generated filename will be of the form $\mathrm{prefixXXXXXX}$.
 • If both a prefix and suffix are provided, then the generated filename will be of the form $\mathrm{prefixXXXXXXsuffix}$. A prefix must be provided if a suffix is to be specified.
 • Each of the functions TemporaryFilename and TemporaryFile guarantees that the filename it returns did not exist at the time it was called. However, it is possible that another process may create this filename in between the call to TemporaryFilename or TemporaryFile and the moment when the file is actually opened.
 • While TemporaryFilename and TemporaryFile do not create the temporary file, they do issue an error if this file could not be created.

Examples

 > $\mathrm{with}\left(\mathrm{FileTools}\right):$

Return a filename that is unique in the current directory.

 > $\mathrm{TemporaryFilename}\left(\right)$
 ${"MaplecAYm9LTV"}$ (1)

Return a unique filename with extension .txt, in the temporary directory.

 > $\mathrm{TemporaryFile}\left("",".txt"\right)$
 ${"/tmp/frlFTfMC.txt"}$ (2)

Return a unique filename with extension .csv, in the home directory of the current user.

 > $\mathrm{TemporaryFile}\left("MyTemp",".csv",\mathrm{directory}=\mathrm{homedir}\right)$
 ${"/home/maple/MyTempyYxVbxdp.csv"}$ (3)

Attempt to create a temporary filename in a non-writable directory.

 > $\mathrm{TemporaryFilename}\left("/"\right)$

Compatibility

 • The FileTools[TemporaryFile] command was introduced in Maple 2017.