RunMat
GitHub

tempdir — Return the system temporary directory path with a trailing platform file separator.

tempdir returns the absolute path of the operating system temporary directory. It follows MATLAB-compatible trailing-separator behavior so file names can be concatenated safely.

Syntax

folder = tempdir()

Returns

NameTypeDescription
folderStringScalarAbsolute path to the system temporary directory with trailing separator.

Errors

IdentifierWhenMessage
Any positional input argument is supplied.tempdir: too many input arguments
OS temporary directory resolution returns an empty path.tempdir: unable to determine temporary directory (OS returned empty path)

How tempdir works

  • The builtin accepts no input arguments; providing any arguments raises tempdir: too many input arguments.
  • The output is a character row vector (1×N) for compatibility with historical MATLAB code. Convert it with string(tempdir) if you prefer string scalars.
  • The path reflects the process environment, honouring variables such as TMPDIR (macOS/Linux) or TMP/TEMP (Windows).
  • When the OS reports a temporary folder that lacks a trailing separator, RunMat appends one automatically to mirror MATLAB.
  • The directory is not created or cleaned automatically; RunMat relies on the operating system to manage the folder lifecycle.
  • If RunMat cannot determine the temporary folder (rare), the builtin raises an error containing the operating system message.

Does RunMat run tempdir on the GPU?

tempdir performs no GPU work. It queries the host environment and surfaces the result as a character array. The builtin registers a CPU-only GPU spec so the fusion planner treats it as a host-side operation. Scripts that accidentally store paths on the GPU have nothing to worry about—tempdir has no inputs to gather.

GPU memory and residency

No. tempdir is always a host operation. There is nothing to gain by moving data to the GPU, and no acceleration provider needs to implement hooks for this builtin.

Examples

Get The System Temporary Folder Path

folder = tempdir();
disp(folder)

Expected output:

/tmp/

Combine tempdir With tempname To Build Unique Paths

uniqueFile = fullfile(tempdir(), "runmat-session.log");
fid = fopen(uniqueFile, "w");
fprintf(fid, "Temporary log created at %s\n", datetime);
fclose(fid)

Expected output:

% Creates runmat-session.log inside the system temporary folder

Create A Temporary Working Subfolder

workDir = fullfile(tempdir(), "mytask");
if ~exist(workDir, "dir")
    mkdir(workDir);
end
disp(workDir)

Expected output:

% Prints the path to tempdir/mytask and creates the folder if needed

Verify That tempdir Appends A File Separator

folder = tempdir();
endsWithSeparator = folder(end) == filesep;
disp(endsWithSeparator)

Expected output:

1

Use tempdir When Creating Temporary Zip Archives

archive = fullfile(tempdir(), "results.zip");
zip(archive, "results");
disp(archive)

Expected output:

% Displays the full path to results.zip inside the system temp folder

Log Temporary Folder Usage For Debugging

fprintf("RunMat temp folder: %s\n", tempdir())

Expected output:

% Prints something like:
%   RunMat temp folder: /tmp/

Using tempdir with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how tempdir changes the result.

Run a small tempdir example, explain the result, then change one input and compare the output.

FAQ

Why does tempdir return a character vector instead of a string scalar?

MATLAB has historically returned character vectors. RunMat mirrors that behaviour for compatibility; wrap the result in string(...) when you need a string scalar.

Does the path include a trailing separator?

Yes. RunMat appends the platform-specific file separator when necessary so you can safely concatenate file names.

What happens if the temporary folder does not exist?

RunMat reports the folder reported by the operating system. Most platforms guarantee the folder exists; if not, subsequent calls such as mkdir can create it.

Can I change the temporary folder location?

Yes. Set TMPDIR (macOS/Linux) or TEMP/TMP (Windows) before starting RunMat. tempdir will honour those environment variables, just like MATLAB.

Will tempdir ever create or clean files automatically?

No. The builtin only reports the path. Cleanup policies remain the responsibility of the operating system or your code.

Is tempdir thread-safe?

Yes. Querying the temporary folder is read-only and does not modify global state.

Does tempdir work inside deployed or sandboxed environments?

As long as the process has permission to query the environment, it returns the best-effort location supplied by the OS.

Can I call tempdir on the GPU?

No. The function is host-only, but it also never transfers data to or from the GPU.

Does tempdir normalize path separators?

RunMat preserves the operating system’s separators (backslash on Windows, slash elsewhere) to maintain MATLAB compatibility.

What if I pass arguments to tempdir by mistake?

RunMat raises tempdir: too many input arguments, matching MATLAB’s diagnostic.

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how tempdir is executed, line by line, in Rust.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.