CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-fs-readdir-recursive

Recursively read a directory and return an array of all file paths

90

1.11x
Overview
Eval results
Files

task.mdevals/scenario-5/

Symlink-Safe Directory Scanner

Build a utility that scans a directory tree and categorizes all discovered items by type, with proper handling of symbolic links.

Requirements

Your solution should provide a function that recursively scans a directory and returns an object containing three arrays:

  • Regular files (including symlinked files)
  • Directories (including symlinked directories)
  • Broken symlinks (symlinks pointing to non-existent targets)

The function should:

  • Accept a root directory path as input
  • Recursively traverse all subdirectories (including those accessed via symlinks)
  • Return relative paths for all discovered items
  • Gracefully handle broken symlinks without throwing errors
  • Exclude hidden files and directories (those starting with '.')

Implementation

@generates

API

/**
 * Scans a directory tree and categorizes items by type.
 *
 * @param {string} rootDir - The root directory to scan
 * @returns {Object} An object with three arrays: files, directories, and brokenLinks
 * @returns {string[]} returns.files - Array of relative paths to regular files (including symlinked files)
 * @returns {string[]} returns.directories - Array of relative paths to directories (including symlinked directories)
 * @returns {string[]} returns.brokenLinks - Array of relative paths to broken symlinks
 */
function categorizeByType(rootDir) {
  // IMPLEMENTATION HERE
}

module.exports = { categorizeByType };

Test Cases

  • Given a directory with regular files, subdirectories, file symlinks, directory symlinks, and broken symlinks, the function returns correctly categorized arrays with relative paths @test
  • Given a directory containing only broken symlinks, the function returns them in the brokenLinks array without throwing errors @test
  • Given an empty directory, the function returns an object with three empty arrays @test

Dependencies { .dependencies }

fs-readdir-recursive { .dependency }

Provides recursive directory reading with symlink support.

Install with Tessl CLI

npx tessl i tessl/npm-fs-readdir-recursive

tile.json