Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/ayonli_jsext/fs.ts>readDir

A JavaScript extension package for building strong and modern applications.
Latest
function readDir
import { readDir } from "https://deno.land/x/ayonli_jsext@v0.9.72/fs.ts";

Reads the directory of the given path and iterates its entries.

NOTE: The order of the entries is not guaranteed.

NOTE: This function can also be used in Cloudflare Workers.

Examples

Example 1

// with the default storage
import { readDir } from "@ayonli/jsext/fs";

for await (const entry of readDir("/path/to/dir")) {
    console.log(`${entry.name} is a ${entry.kind}, its relative path is '${entry.relativePath}'.`);
}

Example 2

// with a user-selected directory as root (Chromium only)
import { readDir } from "@ayonli/jsext/fs";

const root = await window.showDirectoryPicker();
for await (const entry of readDir("/path/to/dir", { root })) {
    console.log(`${entry.name} is a ${entry.kind}, its relative path is '${entry.relativePath}'.`);
}

Example 3

// read the sub-directories recursively
import { readDir } from "@ayonli/jsext/fs";

for await (const entry of readDir("/path/to/dir", { recursive: true })) {
    console.log(`${entry.name} is a ${entry.kind}, its relative path is '${entry.relativePath}'.`);
}

Parameters

target: string | FileSystemDirectoryHandle
optional
options: ReadDirOptions = [UNSUPPORTED]

Returns

AsyncIterableIterator<DirEntry>