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

Method readdirSync

lib/internal/vfs/file_system.js:293–320  ·  view source on GitHub ↗

* Reads directory contents synchronously. * @param {string} dirPath The directory path * @param {object} [options] Options * @returns {string[]|Dirent[]}

(dirPath, options)

Source from the content-addressed store, hash-verified

291 * @returns {string[]|Dirent[]}
292 */
293 readdirSync(dirPath, options) {
294 const providerPath = this.#toProviderPath(dirPath);
295 const result = this[kProvider].readdirSync(providerPath, options);
296
297 // Fix Dirent parentPath from provider-relative to actual VFS path
298 if (options?.withFileTypes === true) {
299 const recursive = options?.recursive === true;
300 for (let i = 0; i < result.length; i++) {
301 const dirent = result[i];
302 if (recursive) {
303 // In recursive mode, name may contain slashes (e.g. 'a/b.txt').
304 // Fix to basename only and set correct parentPath.
305 const slashIdx = dirent.name.lastIndexOf('/');
306 if (slashIdx !== -1) {
307 const subdir = dirent.name.slice(0, slashIdx);
308 dirent.parentPath = joinPath(dirPath, subdir);
309 dirent.name = dirent.name.slice(slashIdx + 1);
310 } else {
311 dirent.parentPath = dirPath;
312 }
313 } else {
314 dirent.parentPath = dirPath;
315 }
316 }
317 }
318
319 return result;
320 }
321
322 /**
323 * Creates a directory synchronously.

Callers 2

rmSyncMethod · 0.95
opendirSyncMethod · 0.95

Calls 2

#toProviderPathMethod · 0.95
sliceMethod · 0.65

Tested by

no test coverage detected