mkdir - Make new directory

Graphical Interface

As an alternative to mkdir, you can use the Current Directory browser to add a directory.

Syntax

mkdir('dirname')
mkdir('parentdir','dirname')
status = mkdir(...,'dirname')
[status,message,messageid] = mkdir(...,'dirname')

Description

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 UNIX[1] platforms.

mkdir('parentdir','dirname') creates the directory dirname in the existing directory parentdir, where parentdir is an absolute or relative path. 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 is successful. It returns logical 0 if the operation is 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.)

Remarks

If an argument specifies a path that includes one or more nonexistent directories, MATLAB attempts to create the nonexistent directory. For example, for

mkdir('mydir\xdir1\xdir2\targetdir')

if xdir1 does not exist, MATLAB creates xdir1, creates xdir2 within xdir1, and creates targetdir within xdir2.

Examples

Creating a Subdirectory in the Current Directory

To create a subdirectory in the current directory called newdir, type

mkdir('newdir')

Creating a Subdirectory in the Specified Parent Directory

To create a subdirectory called newdir in the directory testdata, which is at the same level as the current directory, type

mkdir('../testdata','newdir')

Returning Status When Creating a Directory

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:DirectoryExists

See Also

copyfile, cd, dir, fileattrib, filebrowser, fileparts, ls, mfilename, movefile, rmdir

Managing Files and Working with the Current Directory


[1] UNIX is a registered trademark of The Open Group in the United States and other countries.

  


 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS