Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

mkdir

Make new folder

Syntax

mkdir folderName
mkdir parentFolder folderName
status = mkdir(___)
[status,msg] = mkdir(___)
[status,msg,msgID] = mkdir(___)

Description

example

mkdir folderName creates the folder folderName. If folderName exists, MATLAB® issues a warning. If the operation is not successful, mkdir throws an error to the Command Window.

example

mkdir parentFolder folderName creates the folder folderName in parentFolder. If parentFolder does not exist, MATLAB attempts to create it.

example

status = mkdir(___) creates the specified folder and returns a status of 1 if the operation is successful or if the folder exists. Otherwise, it 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.

example

[status,msg] = mkdir(___) also returns the message text for any warning or error that occurs. You can use this syntax with any of the input argument combinations in the previous syntaxes.

example

[status,msg,msgID] = mkdir(___) also returns the message ID for any warning or error that occurs. You can use this syntax with any of the input argument combinations in the previous syntaxes.

Examples

collapse all

Create a folder called newdir in the current folder.

 mkdir newdir

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

mkdir ../testdata newFolder

Create the same folder twice, verifying the status of the operation after each try.

Create the folder newFolder. The operation succeeds, returning a status of 1, and no error or warning message.

[status, msg, msgID] = mkdir('newFolder')
status = logical
   1

msg =

  0×0 empty char array
msgID =

  0×0 empty char array

Create the folder newFolder once again. The operation once again succeeds, returning a status of 1. A warning message and message ID inform you that the folder already exists.

[status, msg, msgID] = mkdir('newFolder')
status = logical
   1

msg = 
'Directory already exists.'
msgID = 
'MATLAB:MKDIR:DirectoryExists'

Input Arguments

collapse all

Name of the folder to create, specified as a character vector. folderName can be specified as an absolute or relative path, unless a parent folder is specified. If a parent folder is specified, folderName must be a path relative to the parent folder.

If folderName specifies a path that includes one or more nonexistent folders, MATLAB attempts to create the nonexistent folder. For example, for the path myFolder\folder1\folder2\targetFolder, if folder1 does not exist, MATLAB creates folder1, creates folder2 within folder1, and creates targetFolder within folder2.

Name of the parent in which to create the specified folder, specified as a character vector. parentFolder can be specified as an absolute or relative path. If parentFolder does not exist, MATLAB attempts to create it.

Output Arguments

collapse all

Indication of whether the attempt to create the folder is successful, specified as 0 or 1. If the attempt is successful or the folder exists, status is 1. Otherwise, status is 0.

Data Types: logical

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

Error message identifier, specified as a character vector. If an error or warning occurs, msgID contains the message identifier of the error or warning. Otherwise, msgID is empty, ''.

Introduced before R2006a

Was this topic helpful?