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

Run math blazing fast

GitHubX (Twitter)LinkedIn

Company

  • About
  • Pricing
  • Contact

Explore

  • RunMat for academia
  • RunMat vs MATLAB Online
  • Benchmarks

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.

LicensePrivacy
/
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

rmdir — Remove folders with MATLAB-compatible status, message, and message ID outputs.

rmdir removes folders from the filesystem. It follows MATLAB-compatible forms for non-recursive and recursive deletion ('s') and returns status/message/messageID outputs for operational diagnostics.

Syntax

status = rmdir(folderName)
status = rmdir(folderName, flag)
[status, msg, msgID] = rmdir(folderName)
[status, msg, msgID] = rmdir(folderName, flag)

Inputs

NameTypeRequiredDefaultDescription
folderNameStringScalarYes—Folder path to remove.
flagStringScalarYes"s"Recursive flag; only "s" is accepted.

Returns

NameTypeDescription
statusNumericScalar1 on success, 0 when removal fails.
msgStringScalarDiagnostic message for failures.
msgIDStringScalarStable diagnostic identifier string.

Returned values from rmdir depend on how many outputs the caller requests.

Errors

IdentifierWhenMessage
RunMat:rmdir:NotEnoughInputsNo input arguments are provided.rmdir: not enough input arguments
RunMat:rmdir:TooManyInputsMore than two input arguments are provided.rmdir: too many input arguments
RunMat:rmdir:FolderArgTypeFolder argument is not a character vector or string scalar.rmdir: folder name must be a character vector or string scalar
RunMat:rmdir:FlagArgTypeFlag argument is not the scalar character 's'.rmdir: flag must be the character 's' supplied as a char vector or string scalar
RunMat:rmdir:OSErrorFolder removal fails due to filesystem error.rmdir: unable to remove folder
RunMat:rmdir:DirectoryNotFoundTarget folder does not exist.rmdir: directory not found
RunMat:rmdir:NotADirectoryTarget path exists but is not a directory.rmdir: target is not a directory
RunMat:rmdir:DirectoryNotEmptyNon-recursive removal is requested on a non-empty directory.rmdir: directory is not empty
RunMat:rmdir:InvalidFolderNameFolder name is empty.Folder name must not be empty.

How rmdir works

  • status = rmdir(folder) deletes folder only when it exists, is a directory, and is empty. Status outputs are double scalars (1 for success, 0 for failure).
  • [status, message, messageID] = rmdir(folder) returns the diagnostic message and MATLAB-style message identifier. Successful deletions populate both outputs with empty character arrays (1×0).
  • rmdir(folder, 's') removes the folder and all descendants recursively. The flag is case-insensitive and accepts either a char vector or a string scalar with the text "s".
  • Passing a path that does not exist or that resolves to a file returns status = 0 together with descriptive diagnostics. Paths are resolved relative to the current working directory and expand a leading ~ into the user's home directory.
  • Invalid inputs—including numeric arrays, logical values, multi-element string arrays, or empty character vectors—raise MATLAB-style errors before any filesystem work occurs.
  • rmdir automatically gathers GPU-resident path strings (for example, gpuArray("logs")) to host memory before evaluating the filesystem operation. There is no device-side acceleration.

Does RunMat run rmdir on the GPU?

rmdir performs host-side filesystem operations. When acceleration providers are active, RunMat first gathers any GPU-resident arguments, performs the removal on the CPU, and returns host-resident outputs. Providers do not expose special hooks for this builtin, so GPU execution is not applicable.

GPU memory and residency

No. rmdir always executes on the host CPU, therefore placing arguments on the GPU offers no benefit. If a path value is already wrapped in gpuArray, RunMat gathers it automatically before accessing the filesystem so existing scripts continue to work unchanged.

Examples

Remove An Empty Folder

mkdir("scratch");
status = rmdir("scratch")

Expected output:

status =
     1

Remove A Folder And Its Contents

mkdir("data/project");
fid = fopen(fullfile("data/project", "notes.txt"), "w");
fprintf(fid, "Draft notes");
fclose(fid);
status = rmdir("data", "s")

Expected output:

status =
     1

Handle A Missing Folder Gracefully

[status, message, messageID] = rmdir("not-here")

Expected output:

status =
     0
message =
Folder "not-here" does not exist.
messageID =
RunMat:RMDIR:DirectoryNotFound

Detect That A Folder Is Not Empty Without The 's' Flag

mkdir("logs");
fid = fopen(fullfile("logs", "today.log"), "w");
fprintf(fid, "Log entry");
fclose(fid);
[status, message, messageID] = rmdir("logs")

Expected output:

status =
     0
message =
Cannot remove folder "logs": directory is not empty.
messageID =
RunMat:RMDIR:DirectoryNotEmpty

Remove A Directory Specified As A String Scalar On The GPU

mkdir("gpu-folder");
status = rmdir(gpuArray("gpu-folder"))

Expected output:

status =
     1

Capture Status And Message Outputs

mkdir("reports");
[status, message, messageID] = rmdir("reports")

Expected output:

status =
     1
message =

messageID =

Using rmdir with coding agents

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

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

FAQ

What status codes does rmdir return?⌄

1 means the folder was removed (or already absent after a recursive call), while 0 means the folder could not be removed.

Does rmdir throw exceptions?⌄

Only invalid inputs raise errors. Filesystem failures surface through the status, message, and message ID outputs.

How do I remove non-empty folders?⌄

Pass the 's' flag (for example, rmdir("folder", "s")). Without it, rmdir refuses to delete directories that contain files or subfolders.

Is the 's' flag case-sensitive?⌄

No. Use 's' or 'S', supplied as either a char vector or a string scalar with a single element.

Can I target files instead of folders?⌄

No. Passing a file path returns status = 0 with the message ID RunMat:RMDIR:NotADirectory.

How are paths resolved?⌄

Relative paths are resolved against the current working folder (pwd). Leading ~ segments expand to the user's home directory on each platform.

Does rmdir require GPU acceleration?⌄

No. The builtin executes on the host. If an argument resides on the GPU, RunMat gathers it automatically before touching the filesystem.

What happens if the folder is already missing when I pass 's'?⌄

The function reports status = 0 and the message ID RunMat:RMDIR:DirectoryNotFound; it never creates folders.

Can I remove folders using UNC paths or drive letters on Windows?⌄

Yes. The builtin forwards the path to the operating system exactly as MATLAB does.

Why are the message outputs character arrays instead of strings?⌄

MATLAB returns char arrays for compatibility. Wrap them with string(message) if you prefer string scalars.

Related Io functions

Repl Fs

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 · 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 rmdir is executed, line by line, in Rust.

  • View the source for rmdir 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 rmdir works
  • Does RunMat run rmdir on the GPU?
  • GPU memory and residency
  • Examples
  • Remove An Empty Folder
  • Remove A Folder And Its Contents
  • Handle A Missing Folder Gracefully
  • Detect That A Folder Is Not Empty Without The 's' Flag
  • Remove A Directory Specified As A String Scalar On The GPU
  • Capture Status And Message Outputs
  • Using rmdir 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