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

x/ayonli_jsext/esm/fs.js>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/esm/fs.js";

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
optional
options = [UNSUPPORTED]