fullfile — Build a platform-correct file path from multiple path segments.
fullfile joins path segments using the platform-specific file separator, producing a single path string that matches MATLAB semantics. It accepts any number of path segments and returns a character row vector (1xN).
How does the fullfile function behave in MATLAB / RunMat?
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")returnsdata. - 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.
GPU behavior
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 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 of using fullfile in MATLAB / RunMat
Join Relative Path Segments
p = fullfile("data", "raw", "sample.dat")Expected output:
p =
data/raw/sample.datUse fullfile With pwd
root = pwd;
config = fullfile(root, "config", "settings.json")Expected output:
% Returns a full path rooted at the current working folderBuild A Subfolder Path
logDir = fullfile("logs", "2026");
status = mkdir(logDir)Expected output:
status =
1Create 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.datFAQ
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.
See also
Source & Feedback
- Source code: `crates/runmat-runtime/src/builtins/io/repl_fs/fullfile.rs`
- Found a bug? Open an issue with a minimal reproduction.