Remove folder - MATLAB rmdir - MathWorks China (2024)

Remove folder

collapse all in page


rmdir folderName

rmdir folderName s

status = rmdir(___)

[status,msg]= rmdir(___)

[status,msg,msgID]= rmdir(___)



rmdir folderName removesthe folder folderName from the current folder. folderName mustbe empty. If the operation is not successful, MATLAB® throws anerror to the Command Window.


rmdir folderName s also attempts to remove all subfolders and files in folderName, regardless of their write permissions. The result for read-only files follows the practices of the operating system.


status = rmdir(___) removes the specified folder and returns a status of 1 if the operation is successful. Otherwise, rmdir returns 0. Warnings and errors are not thrown to the Command Window. You can use this syntax with any of the input argument combinations in the previous syntaxes.


[status,msg]= rmdir(___) also returns the message text for any warning or error that occurs.


[status,msg,msgID]= rmdir(___) also returns the message ID for any warning or error that occurs.


collapse all

Remove Nonempty Folder

Open Live Script

Remove the folder myfiles, which contains the files myfile1.m and myfile2.m.

Create the folder myfiles and move the files myfile1.m and myfile2.m from the current folder into the new folder.

mkdir myfilesmovefile myfile1.m myfilesmovefile myfile2.m myfiles

Try to remove the folder myfiles using rmdir. Because the myfiles folder is not empty, the operation fails and returns a status of 0 and an error message detailing why the operation failed.

[status, message, messageid] = rmdir('myfiles')
status = logical 0
message = ''myfiles' was not removed. The directory must be empty before removing.'
messageid = 'MATLAB:RMDIR:DirectoryNotRemoved'

Now, use the 's' flag to remove the folder myfiles. A status of 1 and an empty message and messageid indicate that the operation is successful.

[status, message, messageid] = rmdir('myfiles', 's')
message = 0x0 empty char arraymessageid = 0x0 empty char array

Input Arguments

collapse all

folderNameFolder name
character vector | string scalar

Folder name to remove, specified as a character vector or string scalar. Specify folderName as an absolute or relative path.

Data Types: char | string

Output Arguments

collapse all

status — Folder removal status
0 | 1

Status of folder indicating if the attempt to remove the folder is successful, specified as 0 or 1. If the attempt is successful, status is 1. Otherwise, status is 0.

Data Types: logical

msg — Error message
character vector

Error message, specified as a character vector. If an erroror warning occurs, msg contains the message textof the error or warning. Otherwise, msg is empty, ''.

msgID — Error message identifier
character vector

Error message identifier, specified as a character vector. Ifan error or warning occurs, msgID contains themessage identifier of the error or warning. Otherwise, msgID isempty, ''.


  • You can use rmdir to create folders in remote locations. To write to a remote location, folderName or parentName must contain the full path of the file specified as a uniform resource locator (URL) of the form:




    It is also valid to use one or three "slash" (/) characters between schema_name and path_to_file. For example:




    Based on your remote location, schema_name can be one of the values in this table.

    File Systemschema_name
    Amazon S3™s3
    Windows Azure® Blob Storagewasb, wasbs

    As with local folders, rmdir cannot remove nonempty virtual folders unless you specify the s flag. Some file services do not support empty folders. On these services, if rmdir removes folders and leaves their parent folder empty, then the parent folder will be removed as well. For more information, see Work with Remote Data.

Alternative Functionality

In the Current Folder browser, right-click the folder name and select Delete from the context menu. To open the Current Folder browser, use the Current Folder Browser command.

Extended Capabilities

Thread-Based Environment
Run code in the background using MATLAB® backgroundPool or accelerate code with Parallel Computing Toolbox™ ThreadPool.

Version History

Introduced before R2006a

expand all

Starting in R2020a, on UNIX® platforms, the wildcard expression *.* no longer matches folders or files without an extension. In previous releases, the expression matches folders or files regardless of extension, including files without an extension. This change of behavior does not apply to Microsoft® Windows® platforms.

See Also

copyfile | dir | delete | movefile | mkdir | Current Folder Browser

MATLAB Command

You clicked a link that corresponds to this MATLAB command:


Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Remove folder - MATLAB rmdir- MathWorks China (1)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:



Asia Pacific

Contact your local office

Remove folder - MATLAB rmdir
- MathWorks China (2024)


How do I delete a Mathworks folder? ›

In the Current Folder browser, right-click the folder name and select Delete from the context menu. To open the Current Folder browser, use the Current Folder Browser command.

How to remove files from MATLAB path? ›

Remove File from Project
  1. openExample("matlab/TimesTableProjectExample") proj = currentProject;
  2. removeFile(proj,"source/timesTableGame.m")
  3. addFile(proj,"source/timesTableGame.m")

How do I delete a folder in MATLAB online? ›

To delete a folder, use the rmdir function.

How to change MATLAB file path? ›

Change Folders on Search Path Interactively

On the Home tab, in the Environment section, click Set Path. The Set Path dialog box appears. Alternatively, you can access this dialog box using the pathtool function. Use the Add Folder or Add Folder with Subfolders button to add new folders to MATLAB search path.

How do I force Delete a directory in MATLAB? ›

rmdir('dirname',' s ') removes the directory dirname and its contents from the current directory. This removes all subdirectories and files in the current directory regardless of their write permissions.

How to erase a folder? ›

To delete a computer file or folder: Locate the file or folder by using Windows Explorer. To do so, right-click Start and choose Open Windows Explorer and then browse to locate the file you want to delete. In Windows Explorer, right-click the file or folder that you want to delete and then choose Delete.

How to clear path in MATLAB? ›

For general search path cleanup, use the rmpath function or the Set Path dialog box. To open the Set Path dialog box, go to the Home tab and in the Environment section, click Set Path. Alternatively, use the pathtool function.

How do I remove a file from a directory path? ›

After reaching the desired folder, use the del command, followed by the file name.The syntax for deleting a file is: del “filename"For instance, if you want to delete Math_file.txt, run the following command:C:\Users\Reyansh\Documents> del “Math_file.txt”If you receive a prompt to delete the file, type 'Y' and press ' ...

How do I completely remove MATLAB? ›

On Windows® systems, from the list of installed apps, start the interactive uninstaller and follow the prompts to uninstall MATLAB. Windows 10 — From the Windows Start menu, search for Apps & features and open the list of installed apps. Find the MATLAB release you want to uninstall and click Uninstall.

How do I delete a file from MATLAB drive? ›

To delete a file or folder, select it and then click Delete. Deleting a file or folder moves it to the Deleted Files folder. For more information, see Restore Deleted Files in MATLAB Drive Online.

How do I remove folder properties? ›

This might work for you:
  1. left click on file/folder.
  2. right click on the selected file/folder.
  3. left click on Properties.
  4. left click on Details tab.
  5. at the bottom of the window,left click on ---Remove properties and personal information ---
Feb 10, 2023

How do you remove items from the workspace in MATLAB? ›

To clear all variables from the current workspace, use clear or clearvars . To clear all global variables, use clear global or clearvars –global . To clear a particular class, use clear myClass . To clear a particular function or script, use clear functionName .

How to remove folders from path MATLAB? ›

rmpath( folderName ) removes the specified folder from the search path. If folderName is a set of multiple folders separated by path separators, then each of the specified folders will be removed.

Where is MATLAB path file stored? ›

By default, pathdef. m is in matlabroot /toolbox/local . When you change the search path, MATLAB uses it in the current session, but does not update pathdef. m .

How do I change the directory of a folder in MATLAB? ›

Use the cd command to display the new current folder. Change the current folder back to the original folder, using the stored path. Use the cd command to display the new current folder.

How do I Uninstall MathWorks products? ›

To uninstall toolboxes, products, support packages, or other add-ons from MATLAB®, follow these steps:
  1. On the MATLAB Home tab, in the Environment section, click Add-Ons, and then Manage Add-Ons.
  2. In the Add-On Manager window, locate the add-on, and from the ellipsis menu, click Uninstall.

How do I delete MATLAB files? ›

Select MATLAB > General and in the Deleting files section, select from the available options. Alternatively, you can use the recycle function. When file recycling is on, the delete function moves deleted files to a location specific to the platform: Windows® — Recycle bin.

How do I delete my MathWorks account? ›

Direct link to this answer

If you want to close your Mathworks Account: Click on the Profile dropdown in your MathWorks Account and then selecting Close Account from the menu. You can then fill out the form to complete the request to close your account.

How do I remove my license from MathWorks? ›

Deactivate Software
  1. Sign in to ...
  2. Under My Software, click the license you want to deactivate. ...
  3. Click the Install and Activate tab.
  4. Find the activated computer in the list, then click the deactivate icon. ...
  5. Follow all prompts.


Top Articles
Latest Posts
Article information

Author: Tuan Roob DDS

Last Updated:

Views: 5909

Rating: 4.1 / 5 (62 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Tuan Roob DDS

Birthday: 1999-11-20

Address: Suite 592 642 Pfannerstill Island, South Keila, LA 74970-3076

Phone: +9617721773649

Job: Marketing Producer

Hobby: Skydiving, Flag Football, Knitting, Running, Lego building, Hunting, Juggling

Introduction: My name is Tuan Roob DDS, I am a friendly, good, energetic, faithful, fantastic, gentle, enchanting person who loves writing and wants to share my knowledge and understanding with you.