Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/path/mod.ts>Path

better path handling for Deno
Latest
class Path
Re-export
import { Path } from "https://deno.land/x/path@v3.0.0/mod.ts";

this class represents a filesystem path, and allows for easy manipulation of said path

Constructors

new
Path(path?: string, separators?: string[])

construct a path object already with a path or empty

Properties

private
pathElements: string[]
private
separators: string[]
elements: string[]

request the inner representation of the path inside the class

readonly
exists: boolean

Checks if the path exists

const path = new Path("/home/test/text.txt");
path.exists;

requires: --allow-read flag

readonly
ext: string | null

returns the extension or null the dot will not be stripped dotfiles are considered extensionless

readonly
isDir: boolean
readonly
isFile: boolean
separatorList: string[]
trailingSlash: boolean

Methods

removes an element from the end of this path and returns the path to allow for chaining

findLastValidNode(ignoreFiles?: boolean): Promise<Path>

finds the first valid node walking a path from the right

findLastValidNodeSync(ignoreFiles?: boolean): Path

finds the first valid node walking a path from the right synchronously

mkDir(parents?: boolean): Promise<boolean>
mkDirSync(parents?: boolean): boolean

create the specified path if parents is true any needed paths will be created

Pop an element from the path and return the popped element as another Path

push(e: string): Path

push a path fragment onto the end of this Path

rm(recursive?: boolean): Promise<void>

remove self

rmSync(recursive?: boolean): void

remove self sync

toString(
prefix?: string,
suffix?: string,
separator?: string,
): string

render this path object as a string

Static Methods

private
explodePath(separators: string[], pathString: string): string[]

explodes a string into an array of strings

diff(x: Path, y: Path): string[]

takes the diff between Path x and Path y

deprecated
genTmpPath(
rngScalar?: number,
prefix?: string,
suffix?: string,
joinChar?: string,
tmpDir?: string,
): Path

Generate a new random folder name with it's path set to the system temporary folder

makeTmpDir(unnamed 0?: { rngScalar?: number; prefix?: string; suffix?: string; joinChar?: string; tmpDir?: string; }): Path

Generate a new random folder name with it's path set to the system temporary folder