How to use node-dir

Comprehensive node-dir code examples:

How to use node-dir.search:

10
11
12
13
14
15
16
17
18
19
20
21
// Optionally execute a command in each directory
const command = argv.c || argv.command || '';


dir.subdirs(rootDirectory, function(err, subdirs) {
    const gitDirectories = subdirs
        .filter(dir => dir.search(/\.git$/) >= 0)
        .map(dir => path.resolve(process.cwd(), dir.slice(0, dir.length - 4)));


    // Run command in every directory.
    if (command.length) {

How to use node-dir.slice:

11
12
13
14
15
16
17
18
19
20
21
22
const command = argv.c || argv.command || '';


dir.subdirs(rootDirectory, function(err, subdirs) {
    const gitDirectories = subdirs
        .filter(dir => dir.search(/\.git$/) >= 0)
        .map(dir => path.resolve(process.cwd(), dir.slice(0, dir.length - 4)));


    // Run command in every directory.
    if (command.length) {
        gitDirectories.forEach(fullPath => {

How to use node-dir.subdirs:

381
382
383
384
385
386
387
388
389
390
391
    })
  })


const subdirs = (rootdir) =>
  new Promise((resolve, reject) => {
    dir.subdirs(rootdir, (err, subdirs) => {
      if (err) reject(err)
      resolve(subdirs)
    })
  })

How to use node-dir.filesAsync:

185
186
187
188
189
190
191
192
193
var forceWrite = opts.forceWrite;
var lastGlobalUpdate = opts.lastGlobalUpdate;
var ignoreList = opts.ignoreList;
var namePattern = opts.namePattern;

return dir.filesAsync(absDirSrc)
.each(function(absFileSrc) {
  var relFileSrc = path.relative(absDirSrc, absFileSrc);
  var relFileDest = path.join(relDirDest, relFileSrc);

How to use node-dir.promiseFiles:

589
590
591
592
593
594
595
596
597
598
  let appIconsFolder = path.resolve(PieMenuFolder,'icons');    
  return nodeDir.promiseFiles(appIconsFolder);
},
getUserIcons: function(){    
  let userIconsFolder = path.resolve(UserDataFolder,'icons');
  return nodeDir.promiseFiles(userIconsFolder);
},
getLocalIconPath:function(iconFilepath){
  let appIconsFolder = path.resolve(PieMenuFolder,'icons');
  let userIconsFolder = path.resolve(UserDataFolder,'icons');

How to use node-dir.files:

186
187
188
189
190
191
192
193
194
195

/**
 * Make data of navigation and search keywords
 */
function makeNavAndSearchData() {
  const files = nodedir.files(EXAMPLE_FILES_PATH, { sync: true });

  files.forEach((file) => {
    if (file.match(/.html$/)) {
      const filename = getFileName(file);

How to use node-dir.readFiles:

91
92
93
94
95
96
97
98
99
100
}

const generator = (createNode) => (
  Promise.all([
    new Promise((resolve, reject) => {
      dir.readFiles(
        blogConfig.siteBlogPath,
        fileReadingOptions,
        sourceBlogs(createNode),
        resolve