createDirectory(at:withIntermediateDirectories:permissions:)

Create a directory at the given path.

FileSystem.swift:231
iOS
13.0+
macOS
10.15+
tvOS
13.0+
watchOS
6.0+
func createDirectory(at path: FilePath, withIntermediateDirectories createIntermediateDirectories: Bool, permissions: FilePermissions?) async throws

Parameters

path

The directory to create.

createIntermediateDirectories

Whether intermediate directories should be created.

permissions

The permissions to set on the new directory; default permissions will be used if not specified.

If a directory (or file) already exists at path a FileSystemError with code fileAlreadyExists is thrown.

If the parent directory of the directory to created does not exist a FileSystemError with invalidArgument is thrown. Missing directories can be created by passing true to createIntermediateDirectories.

Errors

Error codes thrown include:

  • fileAlreadyExists if a file or directory already exists .

  • invalidArgument if a component in the path prefix does not exist and createIntermediateDirectories is false.

Implementation details

Uses the mkdir(2) system call.