| MATLAB Function Reference | ![]() |
As an alternative to the mkdir function,
you can click the New folder button
in the Current Directory Browser to add a directory.
mkdir('dirname')
mkdir('parentdir','dirname')
status = mkdir(...,'dirname')
[status,message,messageid] = mkdir(...,'dirname')
mkdir('dirname') creates the directory dirname in the current directory, if dirname represents a relative path. Otherwise, dirname represents an absolute path and mkdir attempts to create the absolute directory dirname in the root of the current volume. An absolute path starts with any one of the following: a drive letter on the Microsoft® Windows® platform, a UNC path '\\' string, or a '/' character on The Open Group UNIX® platform.
mkdir('parentdir','dirname') creates the directory dirname in the existing directory parentdir, where parentdir is an absolute or relative pathname. If parentdir does not exist, the MATLAB® software attempts to create it. See the Remarks section below.
status = mkdir(...,'dirname') creates the specified directory and returns a status of logical 1 if the operation was successful, or logical 0 if unsuccessful.
[status,message,messageid] = mkdir(...,'dirname') creates the specified directory, and returns status, message string, and MATLAB error message ID. The value given to status is logical 1 for success and logical 0 for error.
See the help for error and lasterror for more information.)
If the dirname or parentdir argument specifies not only a directory name, but also a directory path (e.g., 'mydir\xdir1\xdir2\targetdir'), and this path includes one or more nonexistent directories (e.g., xdir1 and/or xdir2 in the path above), MATLAB attempts to create each nonexistent parent directory, in turn, in the process of creating the specified target directory.
To create a subdirectory in the current directory called newdir, type
mkdir('newdir')To create a subdirectory called newdir in the directory testdata, which is at the same level as the current directory, type
mkdir('../testdata','newdir')In this example, the first attempt to create newdir succeeds, returning a status of 1, and no error or warning message or message identifier:
[s, mess, messid] = mkdir('../testdata', 'newdir')
s =
1
mess =
''
messid =
''If you attempt to create the same directory again, mkdir again returns a success status, and also a warning and message identifier informing you that the directory already existed:
[s,mess,messid] = mkdir('../testdata','newdir')
s =
1
mess =
Directory "newdir" already exists.
messid =
MATLAB:MKDIR:DirectoryExistscopyfile, cd, dir, fileattrib, filebrowser, fileparts, ls, mfilename, movefile, rmdir
![]() | mislocked | mkdir (ftp) | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |