How to use the files function from node-dir

Find comprehensive JavaScript node-dir.files code examples handpicked from public code repositorys.

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);
fork icon15
star icon100
watch icon13

99
100
101
102
103
104
105
106
107

const Migrate = {
  Migration: Migration,

  assemble: function (options, callback) {
    dir.files(options.migrations_directory, function (err, files) {
      if (err) return callback(err);

      options.allowed_extensions = options.allowed_extensions || /^\.(js|es6?)$/;
fork icon65
star icon99
watch icon9

44
45
46
47
48
49
50
51
52
53
      conn.close();
  })
});

/*Clean out the jsonData dir*/
nodeDir.files(dir, function(err, files) {
  if (err) throw err;
  for(var x = 0; x < files.length; x++){
    fs.unlinkSync(files[x]);
  }
fork icon5
star icon12
watch icon2

373
374
375
376
377
378
379
380
381
382
383
  })
}


const files = (rootdir) =>
  new Promise((resolve, reject) => {
    dir.files(rootdir, (err, files) => {
      if (err) reject(err)
      resolve(files)
    })
  })
fork icon4
star icon13
watch icon0

+ 4 other calls in file

109
110
111
112
113
114
115
116
117
118
 * filenames as names
 */
function processResourceFolder (path, callback) {
  const dirName = getLastPathComponent(path)
  const resType = dirName.split('-')[0]
  dir.files(path, function (err, files) {
    if (err) throw err
    for (let i = 0; i < files.length; i++) {
      if (files[i].match(/\.xml$/i)) {
        const name = getLastPathComponent(files[i]).split('.xml')[0]
fork icon2
star icon6
watch icon0

64
65
66
67
68
69
70
71
72
73
      reject(err);
    }
    resolve(result);
  };
}
dir.files(sourceDir, function(err, files){
    if (err) {
      callback(err);
    }
    if(files === undefined) {
fork icon2
star icon3
watch icon0

100
101
102
103
104
105
106
107
108
109
        return newList;
}

function getFiles( mediaPath, order ) 
{
        let mediaFiles = dir.files( mediaPath, {sync:true, recursive:false});

        let matchs = [/.mp4$/ig, /.rmvb$/ig, /.mkv$/ig];
        let isMediaFile = function(filename) {
                return matchs.some( regex => {
fork icon0
star icon2
watch icon1

676
677
678
679
680
681
682
683
684
685
files: [
    (next) => {
        // recurse into all directories to get complete list of files
        let files = specificFiles || [];
        async.each(directories, (directory, eachNext) => {
            dir.files(directory, (err, dirFiles) => {
                files = files.concat(dirFiles || []);
                eachNext(err);
            });
        }, (err) => {
fork icon1
star icon1
watch icon0

131
132
133
134
135
136
137
138
139
140
141
142


var last_datum = datum;
var files_all = null;


try {
    files_all = dir.files(PFAD_SOURCE, { sync: true });
}
catch(err) {
    console.log(colors.yellow('Keine Dateien in ' + PFAD_SOURCE + ' vorhanden.'));
    console.log(err.message);
fork icon0
star icon0
watch icon1

+ 7 other calls in file

132
133
134
135
136
137
138
139
140
141
142
143


// var picsdirectory = '../pics/';
var files_all = null;


try {
    files_all = dir.files(picsdirectory, { sync: true, recursive: false });
}
catch(err) {
    console.log(picsdirectory + ' nicht vorhanden.')
    console.log(err.message);
fork icon0
star icon0
watch icon1

+ 7 other calls in file

347
348
349
350
351
352
353
354
355
356
357


function getPathList (dir, fileMatch, nameMap) {
    Expect(dir).is.a.String('gPL dir');
    Expect(fileMatch).is.a.String('gPL filematch');
    return new Promise((resolve, reject) => {
        Dir.files(dir, (err, pathList) => {
            if (err) reject(err);
            let match = new RegExp(fileMatch);
            let filtered = _.filter(pathList, path => {
                let filename = Path.basename(path);
fork icon0
star icon0
watch icon2

+ 11 other calls in file

172
173
174
175
176
177
178
179
180
181

var re = new RegExp(/(\d+)(.mp4|.mkv)$/); // movie_id
    json = { movies: [] };

console.log('Generating data for Movies...')
node_dir.files(config.movies.path, function(err, files) {
  if (err) throw err;
  
  bluebird.mapSeries(files, function(file){
  console.log('GET: ' + file);
fork icon0
star icon0
watch icon0

+ 3 other calls in file

29
30
31
32
33
34
35
36
37
38
// init response array
let objects = [];
// int subdir array
subdirs = subdirs.split("/");
// iterate through every file
dir.files(
  path.resolve.apply(null, subdirs), function(err, files) {
    if (err) {console.error(err)}; // rethrow error
    let file;
    for (file of files) {
fork icon0
star icon0
watch icon0

19
20
21
22
23
24
25
26
27
28
29
    })
}


function traverseFolders(folder) {
  return new Promise((resolve, reject) => {
    dir.files(folder, (err, files) => {
      if (err) {
        reject(err)
      }
      return Promise.map(files, f => {
fork icon0
star icon0
watch icon0

61
62
63
64
65
66
67
68
69
70
console.log(clipPath);
if (!fs.existsSync(clipPath)) {
        //fs.mkdirSync(clipPath);
        return;
}
dir.files(clipPath, function(err, files) {
        if (err) throw err;
        clip['youtube'] = [];
        _.each(files, function(absPath) {
                var o = Object.create(null);
fork icon0
star icon0
watch icon2