Create Directory {R}←{X}⎕MKDIR Y
This function creates new directories.
Example
⎕NEXISTS'reports'
0
⎕MKDIR'reports'
⎕NEXISTS'reports'
1 Right Argument
Y is a character vector or scalar containing a single directory name, or a vector of character vectors containing zero or more directory names. Names must conform to the naming rules of the host operating system.
By default, for each name in Y the path must exist and the base name must not exist (see File Name Parts), otherwise an error is signalled. The optional left argument X and the Unique variant option can be used to amend this behaviour.
When multiple names are specified, they are processed in the order given. If an error occurs at any point whilst creating directories, processing immediately stops and an error is signalled. The operation is not atomic; some directories might be created before this happens. In the event of an error, there is no result and, therefore, no indication of how many directories were created before the error occurred.
Left Argument
X is optional, and is a numeric scalar that modifies the default behaviour when the base name in Y already exists and/or the path in Y does not already exist:
X | Effect on Behaviour |
|---|---|
0 (default) | The base name in Y must not exist and the path in Y must exist, otherwise an error is signalled. |
1 | No action is taken if a directory specified by Y already exists (the return value indicates whether a new directory was created). Has no effect when the variant option Unique is set. |
2 | Any part of the paths specified in Y which does not already exist will be created in preparation of creating the corresponding directory. |
3 | Combination of 1 and 2. |
If a directory cannot be created (for example, if a directory with that name already exists, or write access is denied), then an error is signalled.
Examples
⎕NEXISTS '/Users/Pete/Documents/temp'
0
⎕←⎕MKDIR '/Users/Pete/Documents/temp'
1
⎕←⎕MKDIR '/Users/Pete/Documents/temp'
FILE NAME ERROR: /Users/Pete/Documents/temp: Already exists
⎕←⎕MKDIR '/Users/Pete/Documents/temp'
∧
⎕←⎕MKDIR'/Users/Pete/Documents/temp/t1/t2'
FILE NAME ERROR: /Users/Pete/Documents/temp/t1/t2: Unable to create directory
⎕←⎕MKDIR'/Users/Pete/Documents/temp/t1/t2'
∧
⎕←2 ⎕MKDIR'/Users/Pete/Documents/temp/t1/t2'
1
⎕←⎕MKDIR'/Users/Pete/Documents/temp/t1/t2'
FILE NAME ERROR: /Users/Pete/Documents/temp/t1/t2: Already exists
⎕←⎕MKDIR'/Users/Pete/Documents/temp/t1/t2'
∧
⎕←⎕MKDIR'temp1' 'temp2'
1 1 Result
R reports what was created. Both its form and whether it is shy depend on the Unique variant option.
Variant Options
⎕MKDIR supports one variant option, Unique. There is no principal option.
Variant Option: Unique
The Unique variant option (a Boolean) specifies whether the base name (see File Name Parts) in Y is modified so that the name is unique, that is, does not already exist. It also determines the form of the result, which is shy when Unique is 0 and not shy when it is 1. The default is 0.
Unique | Effect on Behaviour | R when Y is a single name | R when Y is a vector of names |
|---|---|---|---|
0 (default) | The directory named in Y is created. | a scalar 1 if a directory was created, or 0 if not | a vector of 1s and 0s with the same length as Y |
1 | The name in Y is extended with random characters to make it unique, and that directory is created. | a character vector containing the name of the directory that was created | a vector of character vectors with the same length as Y |
Example
(⎕MKDIR⍠'Unique'1)'/Users/Pete/Documents/temp/t1/t2'
/Users/Pete/Documents/temp/t1/t2djM0X8