ls — List file and folder names.
ls lists local files and folders, optionally selected by a file, folder, or wildcard name.
Syntax
list = ls()
list = ls(name)Inputs
name- Type
StringScalar- Required
- Yes
- Description
- File, folder, or wildcard name as a character vector or string scalar.
Returns
list- Type
Any- Description
- Platform-formatted character array containing the matching names.
Errors
RunMat:ls:InvalidArity- When
- More than one input is supplied.
- Message
ls: too many input arguments
RunMat:ls:InvalidName- When
- The name input is not a character vector or string scalar.
- Message
ls: name must be a character vector or string scalar
RunMat:ls:TooManyOutputs- When
- More than one output is requested.
- Message
ls: too many output arguments
Paths and patterns
With no input, ls lists the current folder. Pass a character vector or string scalar to list a different folder, one file, or names selected by * and ?. Relative paths use the current folder and a leading ~ uses the active environment.
The implemented API interprets its input as a filesystem name. Unix command flags are not passed to a host shell, and remote URLs are not currently resolved.
Character-array result
When an output is requested, ls returns characters. In RunMat mode the result has one padded row per entry on every platform, which makes the shape deterministic across native and browser execution. Directory names end with the platform file separator and duplicate wildcard matches are removed.
MATLAB compatibility mode preserves the platform-specific layout: Unix-like targets return a separated character vector, while Windows returns one padded row per name. A pattern with no matches returns an empty character array.
Execution boundary
Enumeration uses RunMat's filesystem service on native and browser/WASM targets. Paths must be host text; numeric and provider-resident inputs reject before provider or filesystem access.
Calling ls without an output writes the listing to the active console. Capturing the result suppresses that console rendering.
Examples
List the current folder
root = tempname();
mkdir(root);
fid = fopen(fullfile(root, 'current.txt'), 'w'); fclose(fid);
start = cd(root);
listing = ls;
cd(start);
names = cellstr(listing);
rmdir(root, 's');Expected output:
listing contains current.txtList a folder
root = tempname();
mkdir(root);
fid = fopen(fullfile(root, 'alpha.txt'), 'w'); fclose(fid);
mkdir(fullfile(root, 'nested'));
listing = ls(root);
names = cellstr(listing);
rmdir(root, 's');Expected output:
listing contains alpha.txt and nestedList matching files
root = tempname();
mkdir(root);
fid = fopen(fullfile(root, 'one.m'), 'w'); fclose(fid);
fid = fopen(fullfile(root, 'two.txt'), 'w'); fclose(fid);
listing = ls(fullfile(root, '*.m'));
names = cellstr(listing);
rmdir(root, 's');Expected output:
listing contains one.mList one file
root = tempname();
mkdir(root);
file = fullfile(root, 'payload.dat');
fid = fopen(file, 'w'); fclose(fid);
listing = ls(file);
rmdir(root, 's');Expected output:
listing contains payload.datHandle no matches
root = tempname();
mkdir(root);
listing = ls(fullfile(root, '*.missing'));
rmdir(root);Expected output:
listing is emptyUse the portable row layout
root = tempname();
mkdir(root);
fid = fopen(fullfile(root, 'a.txt'), 'w'); fclose(fid);
fid = fopen(fullfile(root, 'long-name.txt'), 'w'); fclose(fid);
listing = ls(root);
rmdir(root, 's');Expected output:
one padded character row per entryMatch inside nested folders
root = tempname();
mkdir(fullfile(root, 'src'));
fid = fopen(fullfile(root, 'src', 'solver.m'), 'w'); fclose(fid);
listing = ls(fullfile(root, 'src', '*.m'));
rmdir(root, 's');Expected output:
listing contains solver.mUsing ls with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how ls changes the result.
Run a small ls example, explain the result, then change one input and compare the output.
FAQ
Which path values can I pass to ls?⌄
Use a character vector or string scalar. Numeric values, cells, character matrices, and nonscalar string arrays are rejected before filesystem access.
How does ls represent directories?⌄
A directory name ends with the platform's file separator in RunMat's portable row layout.
How does the output differ by compatibility mode?⌄
RunMat mode uses one padded character row per entry on every platform. MATLAB compatibility mode follows the platform-specific MATLAB layout: a separated character vector on Unix-like systems and padded rows on Windows.
Does ls support operating-system flags?⌄
Not currently. The input is interpreted as a file, folder, or wildcard name through RunMat's filesystem service rather than passed to an operating-system shell.
Does ls support remote URLs?⌄
No. The current implementation resolves local paths in the active native or browser filesystem.
Related Io functions
Repl Fs
addpath · cd · copyfile · delete · dir · exist · fileattrib · fileparts · filesep · fullfile · genpath · getenv · getpref · isenv · isfile · isfolder · ispref · matlabroot · memmapfile · memmapfile.subsasgn · memmapfile.subsref · 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
Tabular
arrayDatastore · csvread · csvwrite · detectImportOptions · dlmread · dlmwrite · fileDatastore · getvaropts · parquetDatastore · parquetinfo · parquetread · readcell · readmatrix · readtable · readtimetable · setvaropts · setvartype · spreadsheetImportOptions · writecell · writematrix · writetable · writetimetable · xlsread · xlswrite
Data
commit · data.copy · data.create · data.delete · data.exists · data.export · data.import · data.inspect · data.list · data.move · data.open · DataArray.chunk_shape · DataArray.codec · DataArray.dtype · DataArray.fill · DataArray.name · DataArray.rank · DataArray.read · DataArray.resize · DataArray.shape · DataArray.write · Dataset.array · Dataset.arrays · Dataset.attrs · Dataset.begin · Dataset.get_attr · Dataset.has_array · Dataset.id · Dataset.path · Dataset.refresh · Dataset.set_attr · Dataset.set_attrs · Dataset.snapshot · Dataset.version · DataTransaction.abort · DataTransaction.commit · DataTransaction.create_array · DataTransaction.delete_array · DataTransaction.fill · DataTransaction.id · DataTransaction.resize · DataTransaction.set_attr · DataTransaction.set_attrs · DataTransaction.status · DataTransaction.write
Filetext
fclose · feof · fgetl · fgets · fileread · filewrite · fopen · fprintf · fread · frewind · fwrite · readlines · writelines
Import
Json
Source you can read
Every RunMat function's source is public. Read exactly how ls is executed, line by line, in Rust.
- View the source for ls in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/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.