Skip to content

Path.mkdir() method

pathlib-ts > Path > mkdir

Create a directory with optional parents and existOk semantics.

Signature:

mkdir(options?: {
parents?: boolean;
existOk?: boolean;
mode?: number;
}): Promise<void>;

Parameter

Type

Description

options

{ parents?: boolean; existOk?: boolean; mode?: number; }

(Optional) POSIX-style creation options (parents, existOk, mode).

Returns:

Promise<void>

Promise that settles once the directory exists.

Delegates to Node’s fs.mkdir while matching CPython defaults for parent creation and error handling.

Ensuring nested directories asynchronously

import { Path } from "pathlib-ts";
const assets = new Path("./public/assets/icons");
await assets.mkdir({ parents: true, existOk: true });