RunMat
  • Pricing
RunMat
GitHub
GitHub
DownloadSign InTry in Browser
DesktopRuntimeServer
RunMat

Run math blazing fast

GitHubX (Twitter)LinkedIn

Company

  • About
  • Pricing
  • Contact
  • License
  • Privacy

Learn

  • Docs
  • Blog
  • Benchmarks
  • RunMat vs MATLAB Online

Get product updates and release notes from the RunMat team.

© 2026 Dystr · Made withfor the scientific community.

RunMat™ is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

/
See all docs
Builtin Reference
    • addpath
    • cd
    • copyfile
    • delete
    • dir
    • exist
    • fileattrib
    • fileparts
    • fullfile
    • genpath
    • getenv
    • getpref
    • isenv
    • isfile
    • isfolder
    • ispref
    • ls
    • matlabroot
    • memmapfile
    • mkdir
    • movefile
    • open
    • opentoline
    • path
    • pathsep
    • pcode
    • pwd
    • readstruct
    • rehash
    • restoredefaultpath
    • rmdir
    • rmpath
    • run
    • savepath
    • setenv
    • setpref
    • system
    • tempdir
    • tempname
    • uigetdir
    • uigetfile
    • uiputfile
    • unsetenv
    • userpath
    • what
    • winqueryreg
    • xmlread
    • xmlwrite

genpath — Generate recursive path strings from folder trees in MATLAB and RunMat.

genpath(folder) walks a folder tree and returns a path string containing the folder and subfolders in depth-first order. Path separator and traversal behavior match MATLAB semantics.

Syntax

pathstr = genpath()
pathstr = genpath(folder)
pathstr = genpath(folder, excludes)

Inputs

NameTypeRequiredDefaultDescription
folderStringScalarYes—Root folder to traverse recursively.
excludesStringScalarYes—Path-list string of folders to exclude.

Returns

NameTypeDescription
pathstrStringScalarGenerated recursive path string.

Errors

IdentifierWhenMessage
—The folder argument is not a character vector, string scalar/array scalar, or tensor of character codes.genpath: folder must be a character vector or string scalar
—The excludes argument is not a character vector, string scalar/array scalar, or tensor of character codes.genpath: excludes must be a character vector or string scalar
—More than two positional arguments are provided.genpath: too many input arguments
—Current directory cannot be resolved while locating the traversal root.genpath: unable to resolve current directory
—Requested folder path does not exist.genpath: folder not found

How genpath works

  • genpath() with no inputs uses the current working directory (pwd) as the root folder. genpath(folder) accepts either an absolute or relative path.
  • MATLAB-reserved directories named private or resources, as well as class folders (@MyClass) and namespace folders (+pkg), are skipped automatically along with all of their descendants. The root folder is still included even if it matches one of these reserved names.
  • All returned entries are absolute, canonicalised paths beginning with the root directory, followed by each descendant directory in lexical order. The walking order matches MATLAB's depth-first behaviour.
  • Duplicate directories are removed automatically. Symlinked folders that resolve to the same physical location only appear once in the output.
  • genpath(folder, excludes) omits any folder listed in excludes together with its descendants. The excludes argument is a character vector of absolute or relative paths separated by pathsep. Relative entries are resolved against the supplied root folder before canonicalisation.
  • If a folder in the tree cannot be read (for example due to permissions), RunMat silently skips that branch while keeping the rest of the result intact.
  • If the requested root folder does not exist, RunMat raises genpath: folder '<name>' not found, matching MATLAB error semantics.

Does RunMat run genpath on the GPU?

genpath operates entirely on the host filesystem. Any string inputs that reside on the GPU are gathered back to the CPU before processing. No acceleration provider hooks are invoked and no device kernels are launched.

GPU memory and residency

No. genpath manipulates host-side strings and filesystem metadata. Supplying gpuArray values provides no benefit—RunMat gathers the data automatically.

Examples

Generate a recursive path for the current working folder

p = genpath();
addpath(p);   % Add the current folder and all subfolders to the MATLAB path

Build a search path for a project toolbox

toolboxRoot = "toolbox/signal";
toolboxPath = genpath(toolboxRoot);
addpath(toolboxPath, "-end")

Exclude build output directories from the generated path

root = "projects/solver";
excludes = strjoin([
    fullfile(root, "build"),
    fullfile(root, "dist")
], pathsep);
p = genpath(root, excludes)

Skip a private utilities folder while including the rest of the tree

root = "analysis";
p = genpath(root, fullfile(root, "private"))

Automatically skip MATLAB-reserved folders

root = "toolbox";
mkdir(root, "private");
mkdir(root, "+package");
p = genpath(root)

Expected output:

% `p` only includes `toolbox` and subfolders that are not named `private` or
% `resources`, and that do not begin with `@` or `+`.

Combine genpath with savepath for persistent tooling setup

p = genpath("third_party/toolchain");
addpath(p);
savepath()

Using genpath with coding agents

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

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

FAQ

Does genpath include package (+pkg) and class (@Class) folders?⌄

No. These directories are excluded automatically, along with folders named private or resources. Use the excludes argument for additional rules.

How do I exclude multiple folders?⌄

Build a character vector or string using pathsep (for example, strjoin({path1, path2}, pathsep)) and pass it as the second argument. Relative entries are interpreted relative to the root folder.

Why are some folders missing from the result?⌄

RunMat only omits folders that you explicitly exclude or that cannot be read due to filesystem permissions.

What happens if the root folder does not exist?⌄

genpath raises genpath: folder '<name>' not found, matching MATLAB. Create the folder first or adjust the argument.

Can I call genpath on a GPU array?⌄

Yes—the input is gathered to the CPU before processing, and the result is returned as a standard character vector.

Is the result always absolute paths?⌄

Yes. RunMat resolves the root and all discovered folders to their absolute, canonical locations to avoid duplicates.

Will symbolic links be traversed?⌄

Yes, but the target directory only appears once in the output. Directory cycles are prevented by tracking canonical paths.

Can I feed genpath output directly into addpath or rmpath?⌄

Absolutely. The output string is pathsep-delimited specifically for that purpose.

Related Io functions

Repl Fs

addpath · cd · copyfile · delete · dir · exist · fileattrib · fileparts · fullfile · getenv · getpref · isenv · isfile · isfolder · ispref · ls · matlabroot · memmapfile · mkdir · movefile · open · opentoline · path · pathsep · pcode · pwd · readstruct · rehash · restoredefaultpath · rmdir · rmpath · run · savepath · setenv · setpref · system · tempdir · tempname · uigetdir · uigetfile · uiputfile · unsetenv · userpath · what · winqueryreg · xmlread · xmlwrite

Net

accept · read · readline · tcpclient · tcpserver · write

Tabular

arrayDatastore · csvread · csvwrite · detectImportOptions · dlmread · dlmwrite · fileDatastore · parquetDatastore · parquetinfo · parquetread · readcell · readmatrix · readtable · readtimetable · spreadsheetImportOptions · writecell · writematrix · writetable · writetimetable · xlsread · xlswrite

Audio

audioinfo · audioread

Io

clc · diary · disp · display · format · input

Filetext

fclose · feof · fgetl · fgets · fileread · filewrite · fopen · fprintf · fread · frewind · fwrite · readlines · writelines

Archive

gunzip · gzip · unzip

Hdf5

h5disp · h5info · h5read · h5write · h5writeatt · hdf5info · hdf5read · hdf5write

Import

importdata · textscan

Json

jsondecode · jsonencode

Mat

load · matfile · save

Http

sendmail · urldecode · urlencode · weboptions · webread · websave · webwrite

Open-source implementation

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

  • View the source for genpath in Rust on GitHub
  • Learn how the RunMat runtime works
  • Found a bug? Open an issue with a minimal reproduction.

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.

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • How genpath works
  • Does RunMat run genpath on the GPU?
  • GPU memory and residency
  • Examples
  • Generate a recursive path for the current working folder
  • Build a search path for a project toolbox
  • Exclude build output directories from the generated path
  • Skip a private utilities folder while including the rest of the tree
  • Automatically skip MATLAB-reserved folders
  • Combine genpath with savepath for persistent tooling setup
  • Using genpath with coding agents
  • FAQ
  • Related Io functions
  • Repl Fs
  • Net
  • Tabular
  • Audio
  • Io
  • Filetext
  • Archive
  • Hdf5
  • Import
  • Json
  • Mat
  • Http
  • Open-source implementation
  • About RunMat