dirent.path property to use the renamed dirent.parentPath property when working with directory entries.
What It Does
The codemod transforms:dirent.path→dirent.parentPath- Works with both
fs.readdir()andfs.opendir()APIs
Usage
Examples
Using readdir()
- Promises API
- Callback API
Before
After
Using opendir()
Before
After
What is a Dirent?
ADirent (directory entry) is an object representation of a directory entry, returned by:
fs.readdir()withwithFileTypes: truefs.opendir()and iterating over the directory
Dirent Properties
name- The file name of the directory entryparentPath- The path to the parent directory (formerlypath)isFile()- Returns true if the entry is a fileisDirectory()- Returns true if the entry is a directoryisSymbolicLink()- Returns true if the entry is a symbolic link
Why the Rename?
The property was renamed frompath to parentPath because:
- The value contains the parent directory path, not the entry’s full path
- The old name
pathwas ambiguous and misleading parentPathclearly communicates what the property contains
Getting the Full Path
To get the full path of a directory entry, combineparentPath and name: