mkdir - Make new folder - MATLAB (original) (raw)
Syntax
Description
mkdir [folderName](#f7-607707-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.
mkdir [parentFolder](#f7-607707-parentFolder) [folderName](#f7-607707-folderName)
creates folderName
in parentFolder
. IfparentFolder
does not exist, MATLAB attempts to create it.
[status](#f7-607707-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.
[[status](#f7-607707-status),[msg](#f7-607707-msg)] = mkdir(___)
also returns the message text for any warning or error that occurs.
[[status](#f7-607707-status),[msg](#f7-607707-msg),[msgID](#f7-607707-msgID)] = mkdir(___)
additionally returns the message ID for any warning or error that occurs.
Examples
Create a folder called newdir
in the current folder.
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')
msg =
0×0 empty char array
msgID =
0×0 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')
msg = 'Directory already exists.'
msgID = 'MATLAB:MKDIR:DirectoryExists'
Input Arguments
Folder name, specified as a character vector or string scalar. You can specify folderName
as an absolute or relative path, unless a parent folder is specified. If you specify a parent folder, thenfolderName
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
, iffolder1
does not exist, MATLAB creates folder1
, createsfolder2
within folder1
, and creates targetFolder
withinfolder2
.
Data Types: char
| string
Parent folder for the new folder, specified as a character vector or string scalar. Specify parentFolder
as an absolute or relative path. If parentFolder
does not exist, MATLAB attempts to create it.
Data Types: char
| string
Output Arguments
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,''
.
Tips
- You can use
mkdir
to create folders in remote locations. To write to a remote location,folderName
orparentName
must contain the full path of the file specified as a uniform resource locator (URL) of the form:schemaname://pathtofile/folderName
orschemaname://pathtofile/parentName
It is also valid to use one or three "slash" (/
) characters betweenschemaname
and_pathtofile
_. For example:schemaname:/pathtofile/folderName
orschemaname:///pathtofile/parentName
Based on your remote location,schemaname
can be one of the values in this table.File System schema_name Amazon S3™ s3 Windows Azure® Blob Storage wasb, wasbs HDFS™ hdfs If the file system being used does not support empty folders then attempting to use mkdir
with that service will throw an error. For more information, see Work with Remote Data.
Extended Capabilities
Version History
Introduced before R2006a
This function supports thread-based environments.