Skip to content

Path.unlink() method

pathlib-ts > Path > unlink

Remove this file or link. Use Path.rmdir() for directories.

Signature:

unlink(options?: {
missingOk?: boolean;
}): Promise<void>;

Parameter

Type

Description

options

{ missingOk?: boolean; }

(Optional) Deletion behaviour flags (missingOk).

Returns:

Promise<void>

Promise that settles once the file is removed.

Matches CPython behavior for missingOk, mapping ENOENT to the expected silent outcome.

Removing stale cache asynchronously

import { Path } from "pathlib-ts";
const cache = new Path("./.cache/state.json");
await cache.unlink({ missingOk: true });