How to use the readdirSync function from fs-extra

Find comprehensive JavaScript fs-extra.readdirSync code examples handpicked from public code repositorys.

310
311
312
313
314
315
316
317
318
319
  process.chdir(oldCwd);
  return true;
}

function buildFolderOfPackages() {
  const folders = fs.readdirSync(packageFolder, { withFileTypes: true }).filter(fileName => {
    return (
      fileName.isDirectory() &&
      fs.existsSync(path.join(packageFolder, fileName.name, 'package.json'))
    );
fork icon58
star icon932
watch icon20

180
181
182
183
184
185
186
187
188
189
190
191
}


module.exports.readFile = readFile;


function readAllFiles(dir) {
	const files = fs.readdirSync(dir);
	const certs = [];
	files.forEach((file_name) => {
		const file_path = path.join(dir, file_name);
		logger.debug(' looking at file ::' + file_path);
fork icon522
star icon768
watch icon62

+ 13 other calls in file

394
395
396
397
398
399
400
401
402
403

  return false;
}

// Remove any log files from a previous installation.
fs.readdirSync(root).forEach((file) => {
  if (isErrorLog(file)) {
    fs.removeSync(path.join(root, file));
  }
});
fork icon109
star icon608
watch icon8

+ 14 other calls in file

699
700
701
702
703
704
705
706
707
708

Promise.all([])
    .then(() => fs.remove(fixtureCopyDir))
    .then(() => fs.copy(fixtureDir, fixtureCopyDir))
    .then(() => {
        const depList = fs.readdirSync(
            `${packageDir}/${depsDirName}`,
        );
        assert.deepEqual(
            depList,
fork icon30
star icon115
watch icon0

+ 3 other calls in file

601
602
603
604
605
606
607
608
609
610
611
612
};




DataPacksUtils.prototype.getFilesRecursive = function(srcpath, allFilePaths) {
    try {
        fs.readdirSync(srcpath).filter((file) => {
            var filePath = path.join(srcpath, file);
            var fileStat = fs.statSync(filePath);
            if (fileStat.isFile()) {
                allFilePaths.push(path.join(srcpath, file));
fork icon82
star icon94
watch icon0

+ 19 other calls in file

619
620
621
622
623
624
625
626
627
628

// Read the contents of the book directory.
// For each file in there, if it ends with .md,
// add its name, without the .md, to the files array.
if (fs.lstatSync(bookDirectory).isDirectory()) {
  fs.readdirSync(bookDirectory)
    .forEach(function (file) {
      if (file.match(/\.md$/g)) {
        const fileBasename = file.replace(/\.md$/g, '')
        files.push(fileBasename)
fork icon39
star icon105
watch icon0

+ 9 other calls in file

54
55
56
57
58
59
60
61
62
63
64
65
66


const createData = ({ path, data }) =>
  fs.outputFile(`public${path}`, data, (err) => err && console.error(err))


const getTurtleFiles = function (dirPath, arrayOfFiles) {
  const files = fs.readdirSync(dirPath)
  arrayOfFiles = arrayOfFiles || []


  files.forEach(function (file) {
    if (fs.statSync(dirPath + "/" + file).isDirectory()) {
fork icon21
star icon23
watch icon0

+ 2 other calls in file

16
17
18
19
20
21
22
23
24
25
26
function integrateIcons(projectDir: string) {
  if (!fse.existsSync(projectDir + "/public/icons")) {
    fse.mkdirSync(projectDir + "/public/icons", { recursive: true });
  }


  fse.readdirSync(`${publicDir}/icons`).map((file: string) => {
    const fileContent = fse.readFileSync(publicDir + "/icons/" + file);
    fse.writeFileSync(projectDir + `/public/icons/${file}`, fileContent);
  });
}
fork icon16
star icon291
watch icon5

+ 3 other calls in file

89
90
91
92
93
94
95
96
97
98
    appname
  )
);

// move res.neu or resources.neu to app folder
const resources = fs.readdirSync(
  path.resolve(process.cwd(), "dist", appname)
);
const resourcesFile = resources.find((file) => /res(ources)?/.test(file));
await fs.copy(
fork icon15
star icon187
watch icon0

109
110
111
112
113
114
115
116
117
118

    return Promise.resolve(extensionsArr);
}

async function resolveVscodeExtensions(extensionsArr) {
    for (const extension of fs.readdirSync(extensions())) {
        const extDataPath = extensions(extension, packageJson);
        if (!fs.existsSync(extDataPath)) {
            console.log('No ' + packageJson + ' found for: ' + extension);
            continue;
fork icon32
star icon58
watch icon15

338
339
340
341
342
343
344
345
346
347
		});
	});

	return;
} else {
	mod_files = fs.readdirSync(mod);

	for (let i = 0; i < mod_files.length; i++) {
		if (fs.statSync(path.join(mod, mod_files[i])).isDirectory()) {
			if (fs.existsSync(path.join(mod, mod_files[i], "mod.json")) &&
fork icon17
star icon106
watch icon4

+ 71 other calls in file

13
14
15
16
17
18
19
20
21
22
	this.ssh_keys = Globals.app_config().ssh_keys;

}

getKeyPathsForOwner(owner) {
	var files = fs.readdirSync(this.ssh_keys);
	var result = files.filter(
		file => ((file.indexOf(owner) !== -1) && (file.indexOf(".pub") === -1))
	);
	if (typeof(result) === "undefined") result = 0;
fork icon8
star icon20
watch icon0

+ 3 other calls in file

183
184
185
186
187
188
189
190
191
192
// that has not been verified. Hence, the lines below are removing this library
// from the solcInput file (https://github.com/wighawag/hardhat-deploy/issues/78#issuecomment-786914537)

// Remove __CACHE_BREAKER library from solcInput
const path = `${__dirname}/deployments/${hre.network.name}/solcInputs`;
fs.readdirSync(path).forEach(file => {
  var m = JSON.parse(fs.readFileSync(`${path}/${file}`).toString());
  delete m?.settings?.libraries[""]?.__CACHE_BREAKER__;
  fs.writeFileSync(`${path}/${file}`, JSON.stringify(m));
});
fork icon6
star icon34
watch icon4

+ 2 other calls in file

535
536
537
538
539
540
541
542
543
544
        }
        if(!fs.existsSync(path.join(backendDir, "backup", "plugins"))){
            fs.mkdirSync(path.join(backendDir, "backup", "plugins"));
        }
        req.files.file.mv(path.join(backendDir, "backup", "plugins", req.files.file.name));
        let newSettingsBackups = fs.readdirSync(path.join(backendDir, "backup", "plugins"));
        
        res.send({newbackups:newSettingsBackups});
    }
})
fork icon3
star icon30
watch icon0

+ 27 other calls in file

137
138
139
140
141
142
143
144
145
146
srvcfg = srvcfg.replace(m[0], startServ + m[0])
srvcfg = "// auto-generated! do not edit here\n" + srvcfg

fs.writeFileSync(join(folder, serversname), srvcfg)

const files = fs.readdirSync(folder)
files.sort((a, b) => (a < b ? -1 : a > b ? 1 : 0))

const filecont = {}
for (const fn of files) {
fork icon4
star icon24
watch icon9

+ 5 other calls in file

2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
  }
}

if (((uri.indexOf('.iso') < 0) && (uri.indexOf('.ISO') < 0)) && (stat != undefined && stat.isDirectory())) {
  try {
    var files = libFsExtra.readdirSync(uri);
    for (var i in files) {
      uris = uris.concat(self.scanFolder(uri + '/' + files[i]));
    }
  } catch (e) {
fork icon28
star icon21
watch icon4

+ 2 other calls in file

33
34
35
36
37
38
39
40
41
42
 * @returns {Array} configFiles
 */
function detectConfigs(configPath, configFiles=[]) {
  const stat = fs.statSync(configPath);
  if (stat.isDirectory()) {
    for (const fileName of fs.readdirSync(configPath)) {
      if (fileName === 'node_modules') {
        continue;
      }
      const file = path.join(configPath, fileName);
fork icon5
star icon9
watch icon5

+ 4 other calls in file

164
165
166
167
168
169
170
171
172
173
    experimentalUseImportModule: true,
    ignoreOrder: true,
}) : () => {},
argv.mode === "production" && systemConfig.buildOptions && systemConfig.buildOptions.productionCompress ? new CompressionPlugin() : () => {},
new CopyWebpackPlugin({
    patterns: fs.readdirSync(path.resolve(__dirname, "site", "static", "public")).map(f => ({
        from: `./site/static/public/${f}`
    })),
}),
markoPlugin.browser,
fork icon1
star icon13
watch icon2

1528
1529
1530
1531
1532
1533
1534
1535
1536
1537

}

console.log("✅  External Plugins Installed!");

fs.readdirSync(__dirname + "/../commands").forEach((plugin) => {

    if (path.extname(plugin).toLowerCase() == ".js") {

        require(__dirname + "/../commands/" + plugin);
fork icon9
star icon1
watch icon1

+ 4 other calls in file

541
542
543
544
545
546
547
548
549
// *****
// Collect some info regarding the MODDABLE toolkit

// https://stackoverflow.com/questions/18112204/get-all-directories-within-directory-nodejs
function getDirectories(parent_dir) {
    return fs.readdirSync(parent_dir).filter(function (file) {
        return fs.statSync(path.join(parent_dir,file)).isDirectory();
    });
  }
fork icon6
star icon20
watch icon3

+ 4 other calls in file

function icon

fs-extra.readFileSync is the most popular function in fs-extra (9724 examples)