MCPcopy Index your code
hub / github.com/nodejs/node / readdirRecursive

Function readdirRecursive

lib/internal/fs/promises.js:1617–1690  ·  view source on GitHub ↗
(originalPath, options)

Source from the content-addressed store, hash-verified

1615}
1616
1617async function readdirRecursive(originalPath, options) {
1618 const result = [];
1619 const queue = [
1620 [
1621 originalPath,
1622 await PromisePrototypeThen(
1623 binding.readdir(
1624 originalPath,
1625 options.encoding,
1626 !!options.withFileTypes,
1627 kUsePromises,
1628 ),
1629 undefined,
1630 handleErrorFromBinding,
1631 ),
1632 ],
1633 ];
1634
1635
1636 if (options.withFileTypes) {
1637 while (queue.length > 0) {
1638 // If we want to implement BFS make this a `shift` call instead of `pop`
1639 const { 0: path, 1: readdir } = ArrayPrototypePop(queue);
1640 for (const dirent of getDirents(path, readdir)) {
1641 ArrayPrototypePush(result, dirent);
1642 if (dirent.isDirectory()) {
1643 const direntPath = pathModule.join(path, dirent.name);
1644 ArrayPrototypePush(queue, [
1645 direntPath,
1646 await PromisePrototypeThen(
1647 binding.readdir(
1648 direntPath,
1649 options.encoding,
1650 true,
1651 kUsePromises,
1652 ),
1653 undefined,
1654 handleErrorFromBinding,
1655 ),
1656 ]);
1657 }
1658 }
1659 }
1660 } else {
1661 while (queue.length > 0) {
1662 const { 0: path, 1: readdir } = ArrayPrototypePop(queue);
1663 for (const ent of readdir) {
1664 const direntPath = pathModule.join(path, ent);
1665 const stat = binding.internalModuleStat(direntPath);
1666 ArrayPrototypePush(
1667 result,
1668 pathModule.relative(originalPath, direntPath),
1669 );
1670 if (stat === 1) {
1671 ArrayPrototypePush(queue, [
1672 direntPath,
1673 await PromisePrototypeThen(
1674 binding.readdir(

Callers 1

readdirFunction · 0.70

Calls 4

getDirentsFunction · 0.85
readdirMethod · 0.45
isDirectoryMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…