• Walk a Directory

    Type Parameters

    • Options extends {
          async?: boolean;
          recursive?: boolean;
      }

    Parameters

    • folder: string
    • Optional options: Options

    Returns Options["async"] extends true
        ? AsyncIterable<fs.Dirent>
        : Iterable<fs.Dirent>

    Example

    import { filesystem } from "@rjweb/utils"
    import path from "path"

    for await (const dirent of filesystem.walk('./node_modules', { async: true, recursive: true })) {
    const spaces = path.relative('./node_modules', dirent.path).split(path.sep).length - 1

    console.log(' '.repeat(spaces), dirent.name)
    }

    Since

    1.12.3

    Supports

    nodejs