Make new folder


status = mkdir(___)
[status,message,messageid] = mkdir(___)


mkdir('folderName') creates the folder folderName, where folderName can be an absolute or a relative path.

mkdir('parentFolder','folderName') creates the folder folderName in parentFolder, where parentFolder is an absolute or relative path. If parentFolder does not exist, MATLAB® attempts to create it. See the Tips section.

status = mkdir(___) creates the specified folder. When the operation is successful, it returns a status of logical 1. When the operation is unsuccessful, it returns logical 0.

[status,message,messageid] = mkdir(___) creates the specified folder, and returns the status, message string, and MATLAB message ID. The value given to status is logical 1 for success, and logical 0 for error.


Creating a Subfolder in the Current Folder

Create a subfolder called newdir in the current folder:


Creating a Subfolder in the Specified Parent Folder

Create a subfolder called newFolder in the folder testdata, using a relative path, where newFolder is at the same level as the current folder:


Returning Status When Creating a Folder

In this example, the first attempt to create newFolder succeeds, returning a status of 1, and no error or warning message or message identifier:

[s, mess, messid] = mkdir('../testdata', 'newFolder')
s =
mess =
messid =

Attempt to create the same folder again. mkdir again returns a success status, and also a warning and message identifier informing you that the folder exists:

[s,mess,messid] = mkdir('../testdata','newFolder')
s =
mess =
   Directory "newFolder" already exists.
messid =

More About

collapse all


If an argument specifies a path that includes one or more nonexistent folders, MATLAB attempts to create the nonexistent folder. For example, for


if folder1 does not exist, MATLAB creates folder1, creates folder2 within folder1, and creates targetFolder within folder2.

See Also

| | | | |

Introduced before R2006a

Was this topic helpful?