Skip to main content
This codemod transforms usage of the deprecated dirent.path property to use the renamed dirent.parentPath property when working with directory entries.

What It Does

The codemod transforms:
  • dirent.pathdirent.parentPath
  • Works with both fs.readdir() and fs.opendir() APIs

Usage

Examples

Using readdir()

Before
After

Using opendir()

Before
After

What is a Dirent?

A Dirent (directory entry) is an object representation of a directory entry, returned by:
  • fs.readdir() with withFileTypes: true
  • fs.opendir() and iterating over the directory

Dirent Properties

  • name - The file name of the directory entry
  • parentPath - The path to the parent directory (formerly path)
  • isFile() - Returns true if the entry is a file
  • isDirectory() - Returns true if the entry is a directory
  • isSymbolicLink() - Returns true if the entry is a symbolic link
Use withFileTypes: true with readdir() to get Dirent objects instead of strings. This provides file type information without additional stat() calls.

Why the Rename?

The property was renamed from path to parentPath because:
  • The value contains the parent directory path, not the entry’s full path
  • The old name path was ambiguous and misleading
  • parentPath clearly communicates what the property contains
The path property was deprecated in Node.js v20.x. Use parentPath to ensure compatibility with future Node.js versions.

Getting the Full Path

To get the full path of a directory entry, combine parentPath and name:

Common Use Cases

Filtering Files by Type

Recursive Directory Traversal

Deprecation Reference

This migration addresses DEP0178.