Represents a path on the file system.
append(data: Uint8Array,options?: Omit<Deno.WriteFileOptions, "append">,): Promise<this>
Appends the provided bytes to the file.
appendSync(data: Uint8Array,options?: Omit<Deno.WriteFileOptions, "append">,): this
Synchronously appends the provided bytes to the file.
appendText(text: string,options?: Omit<Deno.WriteFileOptions, "append">,): Promise<this>
Appends the provided text to the file.
appendTextSync(text: string,options?: Omit<Deno.WriteFileOptions, "append">,): this
Synchronously appends the provided text to the file.
Changes the ownership permissions of the file.
Synchronously changes the ownership permissions of the file.
Iterates over the components of a path.
Copies a file or directory to the provided destination.
Copies the file to the specified destination path.
copyFileSync(destinationPath: ): Path
Copies the file to the destination path synchronously.
Copies the file to the specified directory.
copyFileToDirSync(destinationDirPath: ): Path
Copies the file to the specified directory synchronously.
Copies a file or directory to the provided destination synchronously.
Copies the file or directory to the specified directory synchronously.
Creates a new file or opens the existing one.
Creates a file throwing if a file previously existed.
Synchronously creates a file throwing if a file previously existed.
Synchronously creates a new file or opens the existing one.
Gets the directory path. In most cases, it is recommended
to use .parent()
instead since it will give you a PathRef
.
Ensures that a directory is empty. Deletes directory contents if the directory is not empty. If the directory does not exist, it is created. The directory itself is not deleted.
emptyDirSync(): this
Synchronous version of emptyDir()
Gets if the provided path ends with the specified Path, URL, or string.
This verifies based on matching the components.
assert(new Path("/a/b/c").endsWith("b/c")); assert(!new Path("/a/b/example").endsWith("ple"));
Ensures that the directory exists. If the directory structure does not exist, it is created. Like mkdir -p.
ensureDirSync(): this
Synchronously ensures that the directory exists. If the directory structure does not exist, it is created. Like mkdir -p.
ensureFile(): Promise<this>
Ensures that the file exists. If the file that is requested to be created is in directories that do not exist these directories are created. If the file already exists, it is NOTMODIFIED.
ensureFileSync(): this
Synchronously ensures that the file exists. If the file that is requested to be created is in directories that do not exist these directories are created. If the file already exists, it is NOTMODIFIED.
ensureRemove(options?: Deno.RemoveOptions): Promise<this>
Removes the file or directory from the file system, but doesn't throw when the file doesn't exist.
ensureRemoveSync(options?: Deno.RemoveOptions): this
Removes the file or directory from the file system, but doesn't throw when the file doesn't exist.
Synchronously gets if the path exists. Beware of TOCTOU issues.
Returns the extension of the path with leading period or undefined if there is no extension.
Gets if this path is an absolute path.
Follows symlinks and gets if this path is a file.
Gets if this path is relative.
Gets if this path is a symlink.
Creates a hardlink to the provided target path.
linkToSync(targetPath: ): void
Synchronously creates a hardlink to the provided target path.
lstat(): Promise<Deno.FileInfo | undefined>
Resolves the Deno.FileInfo
of this path without
following symlinks.
lstatSync(): Deno.FileInfo | undefined
Synchronously resolves the Deno.FileInfo
of this path
without following symlinks.
mkdir(options?: Deno.MkdirOptions): Promise<this>
Creates a directory at this path.
mkdirSync(options?: Deno.MkdirOptions): this
Synchronously creates a directory at this path.
Normalizes the path
, resolving '..'
and '.'
segments.
Note that resolving these segments does not necessarily mean that all will be eliminated.
A '..'
at the top-level will be preserved, and an empty path is canonically '.'
.
open(options?: Deno.OpenOptions): Promise<FsFileWrapper>
Opens a file.
openSync(options?: Deno.OpenOptions): FsFileWrapper
Opens a file synchronously.
Gets the parent directory or returns undefined if the parent is the root directory.
Gets the parent or throws if the current directory was the root.
pipeTo(dest: WritableStream<Uint8Array>,options?: StreamPipeOptions,): Promise<this>
Opens the file and pipes it to the writable stream.
readBytes(options?: Deno.ReadFileOptions): Promise<Uint8Array>
Reads the bytes from the file.
Synchronously reads the bytes from the file.
readDirFilePaths(): AsyncIterable<Path>
Reads only the directory file paths, not including symlinks.
readDirFilePathsSync(): Iterable<Path>
Synchronously reads only the directory file paths, not including symlinks.
readDirSync(): Iterable<DirEntry>
Synchronously reads the entries in the directory.
readJson<T>(options?: Deno.ReadFileOptions): Promise<T>
Reads and parses the file as JSON, throwing if it doesn't exist or is not valid JSON.
readJsonSync<T>(): T
Synchronously reads and parses the file as JSON, throwing if it doesn't exist or is not valid JSON.
readMaybeBytes(options?: Deno.ReadFileOptions): Promise<Uint8Array | undefined>
Calls .readBytes()
, but returns undefined if the path doesn't exist.
readMaybeBytesSync(): Uint8Array | undefined
Calls .readBytesSync()
, but returns undefined if the path doesn't exist.
readMaybeJson<T>(options?: Deno.ReadFileOptions): Promise<T | undefined>
Calls .readJson()
, but returns undefined if the file doesn't exist.
readMaybeJsonSync<T>(): T | undefined
Calls .readJsonSync()
, but returns undefined if the file doesn't exist.
readMaybeText(options?: Deno.ReadFileOptions): Promise<string | undefined>
Calls .readText()
, but returns undefined when the path doesn't exist.
readMaybeTextSync(): string | undefined
Calls .readTextSync()
, but returns undefined when the path doesn't exist.
readText(options?: Deno.ReadFileOptions): Promise<string>
Reads the text from the file.
Synchronously reads the text from the file.
realPathSync(): Path
Synchronously resolves to the absolute normalized path, with symbolic links resolved.
Gets the relative path from this path to the specified path.
remove(options?: Deno.RemoveOptions): Promise<this>
Removes the file or directory from the file system.
removeSync(options?: Deno.RemoveOptions): this
Removes the file or directory from the file system synchronously.
Moves the file or directory returning a promise that resolves to the renamed path.
renameSync(newPath: ): Path
Moves the file or directory returning the renamed path synchronously.
Moves the file or directory to the specified directory.
renameToDirSync(destinationDirPath: ): Path
Moves the file or directory to the specified directory synchronously.
Resolves this path to an absolute path along with the provided path segments.
startsWith(path: ): boolean
Gets if the provided path starts with the specified Path, URL, or string.
This verifies based on matching the components.
assert(new Path("/a/b/c").startsWith("/a/b")); assert(!new Path("/example").endsWith("/exam"));
stat(): Promise<Deno.FileInfo | undefined>
Resolves the Deno.FileInfo
of this path following symlinks.
statSync(): Deno.FileInfo | undefined
Synchronously resolves the Deno.FileInfo
of this
path following symlinks.
symlinkTo(opts: SymlinkOptions,): Promise<void>
Creates a symlink to the provided target path.
symlinkTo(target: string,opts?: Partial<SymlinkOptions>,): Promise<void>
Creates a symlink at the provided path with the provided target text.
symlinkToSync(opts: SymlinkOptions,): void
Synchronously creates a symlink to the provided target path.
symlinkToSync(target: string,opts?: Partial<SymlinkOptions>,): void
Synchronously creates a symlink at the provided path with the provided target text.
withBasename(basename: string): Path
Gets a new path reference with the provided file or directory name.
withExtname(ext: string): Path
Gets a new path reference with the provided extension.
write(data: Uint8Array,options?: Deno.WriteFileOptions,): Promise<this>
Writes out the provided bytes or text to the file.
writeJson(obj: unknown,options?: Deno.WriteFileOptions,): Promise<this>
Writes out the provided object as compact JSON.
writeJsonPretty(obj: unknown,options?: Deno.WriteFileOptions,): Promise<this>
Writes out the provided object as formatted JSON.
writeJsonPrettySync(obj: unknown,options?: Deno.WriteFileOptions,): this
Synchronously writes out the provided object as formatted JSON.
writeJsonSync(obj: unknown,options?: Deno.WriteFileOptions,): this
Synchronously writes out the provided object as compact JSON.
writeSync(data: Uint8Array,options?: Deno.WriteFileOptions,): this
Synchronously writes out the provided bytes or text to the file.
writeText(text: string,options?: Deno.WriteFileOptions,): Promise<this>
Writes the provided text to this file.
writeTextSync(text: string,options?: Deno.WriteFileOptions,): this
Synchronously writes the provided text to this file.
instanceofSymbol
This is a special symbol that allows different versions of
Path
API to match on instanceof
checks. Ideally
people shouldn't be mixing versions, but if it happens then
this will maybe reduce some bugs.
[Symbol.hasInstance](instance: unknown): boolean