Dismiss
  • Toggle Theme
  • View as Mobile

Scan a directory and return the file names in Node

This will scan a given directory and return a list of files in that directory.

var fs = require('fs'); // core node file system module
var listOfFilesInDirectory = fs.readdirSync('path/to/directory').filter(function(x) {
  return x !== '.DS_Store' && x !== 'ignore-other-file.js';
});

I'm excluding files that match .DS_Store and ignore-other-file.js.