tempname
Returns a unique name for a temporary file.
Category: Programming > Files and Folders
Syntax
f = tempname
Returns a full path inside the temporary folder.
f = tempname(folder)
Builds the name inside folder instead.
Description
tempname only chooses a name; it does not create the file. Every call returns a new name, so two calls never collide. After using the file, remove it with delete.
Input arguments
folder- Folder to use instead of the temporary folder.
Output arguments
f- Path of a file that does not exist yet.
Example
A name, a file, and cleanup
f = tempname;
isfile(f)
writelines('scratch', f);
isfile(f)
delete(f);
isfile(f)
Output
ans = logical
0
ans = logical
1
ans = logical
0