Skip to Main Content Skip to Search
Product Documentation

mkdir - Make new folder

Alternatives

As an alternative to mkdir, use the Current Folder browser.

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.

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.

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

See Also

cd | copyfile | dir | ls | movefile | rmdir

How To

  


Free MATLAB Interactive Kit

Explore how to use MATLAB to make advancements in engineering and science.


Download free kit

Trials Available

Try the latest version of MATLAB and other MathWorks products.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS