Creating and deleting directories files and folders in Matlab

Here I will explain how to create and delete files or directories in Matlab. This can be used to copy or move files as well. In fact, Matlab can issue any system command. I will show how to do it on Linux platform since its what I use everyday. Basically, we can use a default Matlab function that is called system. It executes a command just like if you were typing it in the terminal.

To create a directory:

system('mkdir my_new_directory_name');

Now lets try to save the output of the system command in Matlab. Lets try to list whats inside the current directory using ls command.


Now lets look at the output:

status =
result =

The current directory now contains my_new_directory_name as expected!

Now lets move into this directory

system('cd my_new_directory_name');


You can programatically issue commands:

command=['mkdir ',folder_name]

We have just created the folder “folder1” !

One thought on “Creating and deleting directories files and folders in Matlab

Leave a Reply

Your email address will not be published. Required fields are marked *