dir — List files and folders with metadata.
dir lists local files and folders and returns their names, containing folders, modification times, sizes, and directory flags.
Syntax
listing = dir()
listing = dir(name)
listing = dir(folder, pattern)Inputs
name- Type
StringScalar- Required
- Yes
- Description
- File, folder, or wildcard path as a character vector or string scalar.
pattern- Type
StringScalar- Required
- Yes
- Description
- RunMat-only wildcard pattern evaluated within the first folder input.
Returns
listing- Type
Any- Description
- Column struct array with name, folder, date, bytes, isdir, and datenum fields.
Errors
RunMat:dir:InvalidArity- When
- More than two inputs are supplied.
- Message
dir: too many input arguments
RunMat:dir:InvalidName- When
- The name input is not a character vector or string scalar.
- Message
dir: name must be a character vector or string scalar
RunMat:dir:InvalidFolder- When
- The first input in the two-input form is not a character vector or string scalar.
- Message
dir: folder must be a character vector or string scalar
Paths and patterns
With no input, dir lists the current folder. A file path returns one metadata record; a folder path lists that folder; and *, ?, and supported ** components select matching entries. Relative paths use the current folder and a leading ~ uses the active environment.
dir(folder, pattern) keeps the base folder and wildcard separate. This two-input convenience form is available in RunMat mode; use dir(fullfile(folder, pattern)) for source that must remain within the MATLAB-compatible subset.
Returned metadata
The column result has name, folder, date, bytes, isdir, and datenum fields. folder is the absolute containing folder, bytes is a double byte count, isdir is logical, and the date fields describe the last observed modification time.
A folder listing includes . and ... A missing well-formed path or wildcard with no matches returns an empty result. Results use platform-aware name ordering.
Execution boundary
Directory enumeration and metadata lookup use RunMat's filesystem service on native and browser/WASM targets. Remote HTTP, HTTPS, authenticated, FTP, and SFTP locations are not currently resolved by this builtin.
Paths must be host text. Numeric and provider-resident inputs reject before provider or filesystem access; dir is not an accelerator or fusion operation.
Examples
List the current folder
root = tempname();
mkdir(root);
fid = fopen(fullfile(root, 'current.txt'), 'w'); fclose(fid);
start = cd(root);
listing = dir;
cd(start);
found = false;
for k = 1:numel(listing)
found = found || strcmp(listing(k).name, 'current.txt');
end
rmdir(root, 's');Expected output:
listing includes current.txtList a folder
root = tempname();
mkdir(root);
fid = fopen(fullfile(root, 'alpha.txt'), 'w'); fclose(fid);
mkdir(fullfile(root, 'nested'));
listing = dir(root);
found_alpha = false;
found_nested = false;
for k = 1:numel(listing)
found_alpha = found_alpha || strcmp(listing(k).name, 'alpha.txt');
found_nested = found_nested || strcmp(listing(k).name, 'nested');
end
rmdir(root, 's');Expected output:
listing includes alpha.txt and nestedInspect one file
root = tempname();
mkdir(root);
file = fullfile(root, 'payload.bin');
fid = fopen(file, 'w'); fwrite(fid, uint8([1 2 3])); fclose(fid);
info = dir(file);
rmdir(root, 's');Expected output:
info describes payload.binMatch a wildcard
root = tempname();
mkdir(root);
fid = fopen(fullfile(root, 'first.m'), 'w'); fclose(fid);
fid = fopen(fullfile(root, 'notes.txt'), 'w'); fclose(fid);
listing = dir(fullfile(root, '*.m'));
rmdir(root, 's');Expected output:
listing contains first.mMatch within a folder
root = tempname();
mkdir(root);
fid = fopen(fullfile(root, 'one.csv'), 'w'); fclose(fid);
fid = fopen(fullfile(root, 'two.txt'), 'w'); fclose(fid);
listing = dir(root, '*.csv');
rmdir(root, 's');Expected output:
listing contains one.csvHandle no matches
root = tempname();
mkdir(root);
listing = dir(fullfile(root, '*.missing'));
rmdir(root);Expected output:
listing is emptyRead metadata fields
root = tempname();
mkdir(root);
fid = fopen(fullfile(root, 'sample.dat'), 'w'); fclose(fid);
info = dir(fullfile(root, 'sample.dat'));
rmdir(root, 's');Expected output:
info contains the standard metadata fieldsUsing dir with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how dir changes the result.
Run a small dir example, explain the result, then change one input and compare the output.
FAQ
Which path values can I pass to dir?⌄
Use a character vector or string scalar containing a local file, folder, or wildcard path. Numeric values, cells, character matrices, and nonscalar string arrays are rejected before filesystem access.
Why do folder listings contain . and ..?⌄
The compatible folder-listing form includes the current-folder and parent-folder entries. Wildcard results contain only entries matched by the pattern.
Does dir support recursive wildcards?⌄
The ** form traverses subfolders when it appears as a complete path component. Ordinary * and ? patterns match within one directory level.
Does dir support remote URLs?⌄
Not yet. This implementation reads through RunMat's native or browser filesystem service and currently resolves local filesystem paths only.
Can dir inspect a gpuArray path?⌄
No. Paths are host text. Numeric and provider-resident values are rejected without an implicit device transfer.
Related Io functions
Repl Fs
addpath · cd · copyfile · delete · exist · fileattrib · fileparts · filesep · fullfile · genpath · getenv · getpref · isenv · isfile · isfolder · ispref · ls · 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 dir is executed, line by line, in Rust.
- View the source for dir 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.