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')) );
58
932
20
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);
522
768
62
+ 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)); } });
109
608
8
+ 14 other calls in file
GitHub: mgol/check-dependencies
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,
30
115
0
+ 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));
82
94
0
+ 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)
39
105
0
+ 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()) {
21
23
0
+ 2 other calls in file
GitHub: remix-pwa/remix-pwa
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); }); }
16
291
5
+ 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(
15
187
0
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;
32
58
15
GitHub: 0neGal/viper
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")) &&
17
106
4
+ 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;
8
20
0
+ 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)); });
6
34
4
+ 2 other calls in file
GitHub: GreySole/Spooder
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}); } })
3
30
0
+ 27 other calls in file
GitHub: microsoft/devicescript
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) {
4
24
9
+ 5 other calls in file
GitHub: volumio/volumio3-backend
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) {
28
21
4
+ 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);
5
9
5
+ 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,
1
13
2
GitHub: prabathLK/PRABATH-MD
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);
9
1
1
+ 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(); }); }
6
20
3
+ 4 other calls in file
fs-extra.readFileSync is the most popular function in fs-extra (9724 examples)