FileTools - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : Input and Output : File Manipulation : FileTools : FileTools/TemporaryFilename

FileTools

  

TemporaryFilename

  

return a filename that may be used for a temporary file

  

TemporaryFile

  

return a file path that may be used for a temporary file

 

Calling Sequence

Parameters

Options

Description

Examples

Compatibility

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 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 file name will be of the form prefixXXXXXX.

• 

If both a prefix and suffix are provided, then the generated file name will be of the form 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

withFileTools:

Return a filename that is unique in the current directory.

TemporaryFilename

MaplecAYm9LTV

(1)

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

TemporaryFile,.txt

/tmp/frlFTfMC.txt

(2)

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

TemporaryFileMyTemp,.csv,directory=homedir

/home/maple/MyTempyYxVbxdp.csv

(3)

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

TemporaryFilename/

Error, permission denied

Compatibility

• 

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

• 

For more information on Maple 2017 changes, see Updates in Maple 2017.

See Also

file_types

FileTools

FileTools[Binary][Close]

FileTools[Binary][OpenTemporaryFile]

FileTools[TemporaryDirectory]

FileTools[Text][Close]

FileTools[Text][OpenTemporaryFile]

IO_errors