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 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, mkdir returns 0 and does not throw a warning or error 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.

example

[status,msg,msgID] = mkdir(___) additionally returns the message ID for any warning or error that occurs.

Examples

collapse all

Create a folder called newdir in the current folder.

 mkdir newdir

Create a folder called newfolder in the folder testdata. Use 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 with no error or warning message.

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

msg =

  0x0 empty char array


msgID =

  0x0 empty char array

Create the folder newFolder again. The operation succeeds again, 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

Folder name, specified as a character vector. You can specify folderName as an absolute or relative path, unless a parent folder is specified. If you specify a parent folder, then folderName must be a path relative to the parent folder.

If folderName contains 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.

Parent folder for the new folder, specified as a character vector. Specify parentFolder as an absolute or relative path. If parentFolder does not exist, MATLAB attempts to create it.

Output Arguments

collapse all

Folder creation status indicating whether the attempt to create the folder is successful, returned as 0 or 1. If the attempt to create the folder is successful or the folder already exists, then the value of status is 1. Otherwise, the value is 0.

Data Types: logical

Error message, returned 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, returned 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?