fullfile — Build platform-correct file paths from path segments in MATLAB and RunMat.

fullfile joins path segments using the platform-specific separator to produce a single path string. It accepts any number of segments and returns a character row vector, with separator normalization and empty-segment handling matching MATLAB semantics.

Syntax

file = fullfile(part1)
file = fullfile(part1, part2, ...)

Inputs

NameTypeRequiredDefaultDescription
part1StringScalarYesFirst path component.
partNStringScalarVariadicAdditional path components.

Returns

NameTypeDescription
fileStringScalarPlatform-correct joined path.

Errors

IdentifierWhenMessage
No path arguments are supplied.fullfile: not enough input arguments
A path argument is not a character vector, string scalar/array scalar, or tensor of character codes.fullfile: arguments must be character vectors or string scalars

How fullfile works

  • fullfile(part1, part2, ...) joins the inputs with the platform file separator (/ on macOS and Linux, \ on Windows).
  • Absolute path segments reset the accumulated path, mirroring MATLAB and OS path rules.
  • Empty segments are ignored, so fullfile("", "data") returns data.
  • Inputs must be character vectors or string scalars. Single-element string arrays are accepted. Other input types raise fullfile: arguments must be character vectors or string scalars.
  • The output is a character vector. Wrap the result with string(...) if you prefer string scalars.

Does RunMat run fullfile on the GPU?

fullfile performs string manipulation on the CPU only. Any GPU-resident inputs are gathered to the host before path assembly so the resulting character vector is always in CPU memory.

GPU memory and residency

No. fullfile is a host-side path builder. GPU-resident text inputs are gathered automatically, so there is no benefit to keeping path strings on the GPU.

Examples

Join Relative Path Segments

p = fullfile("data", "raw", "sample.dat")

Expected output:

p =
    data/raw/sample.dat

Use fullfile With pwd

root = pwd;
config = fullfile(root, "config", "settings.json")

Expected output:

% Returns a full path rooted at the current working folder

Build A Subfolder Path

logDir = fullfile("logs", "2026");
status = mkdir(logDir)

Expected output:

status =
     1

Create A File In A Nested Folder

mkdir(fullfile("data", "raw"));
fid = fopen(fullfile("data", "raw", "sample.dat"), "w");
fclose(fid)

Expected output:

% Creates data/raw/sample.dat

Using fullfile with coding agents

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

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

FAQ

Why does fullfile return a character vector instead of a string?

MATLAB returns character vectors for fullfile. RunMat mirrors that behavior for compatibility; use string(fullfile(...)) if you prefer string scalars.

Does fullfile expand ~ to the home directory?

No. fullfile performs string assembly only. Use cd or filesystem APIs that expand ~ when you need home expansion.

What happens if a segment is absolute?

Absolute segments reset the accumulated path, matching MATLAB and OS path rules.

Can I pass numeric character codes?

Yes. Numeric arrays that represent character codes are accepted as long as they form a row vector, just like other RunMat text inputs.

Does fullfile run on the GPU?

No. It is a host-only utility and gathers GPU-resident inputs before processing.

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how fullfile 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.