mkdir

Make new folder

Syntax

mkdir('folderName')
mkdir('parentFolder','folderName')
status = mkdir(___)
[status,message,messageid] = mkdir(___)

Description

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.

Examples

Creating a Subfolder in the Current Folder

Create a subfolder called newdir in the current folder:

mkdir('newdir')

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:

mkdir('../testdata','newFolder')

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 =
   1
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 =
   1
mess =
   Directory "newFolder" already exists.
messid =
   MATLAB:MKDIR:DirectoryExists

More About

expand all

Tips

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

mkdir('myFolder\folder1\folder2\targetFolder')

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

See Also

| | | | |

Was this topic helpful?