list-filepaths v1.6.5
list-filepaths
Asynchronously return an array containing the paths of all files in a directory and its subdirectories
Install
$ npm install list-filepaths --saveUsage
For a directory tree...
└─┬ episode-v
└─┬ ships
├─┬ millennium-falcon
│ ├── millennium-falcon.js
│ └─┬ pilots
│ ├── chewbacca.js
│ └── han-solo.js
├─┬ slave-i
│ ├─┬ pilots
│ │ └── boba-fett.js
│ └── slave-i.js
└──t-47Return a Promise that is resolved with an alphabetically-sorted array of the paths of all files in a directory and its subdirectories. An options object can be passed as a second argument to filter the results, reject matching paths, or to return relative file paths instead of absolute file paths.
const listFilepaths = require('list-filepaths');
// Inside episode-v
listFilepaths('./ships')
.then(filepaths => {
// Process filepaths
console.log(filepaths);
})
.catch(err => {
// Handle errors
console.error(err);
});
// [
// '/episode-v/ships/millennium-falcon/millennium-falcon.js',
// '/episode-v/ships/millennium-falcon/pilots/chewbacca.js',
// '/episode-v/ships/millennium-falcon/pilots/han-solo.js',
// '/episode-v/ships/slave-i/pilots/boba-fett.js',
// '/episode-v/ships/slave-i/slave-i.js'
// ]API
const listFilepaths = require('list-filepaths');listFilepaths(directoryPath, options)
Returns a Promise that is resolved with an array containing the absolute paths of all files in the target directory and its subdirectories or null if no file paths are found. File paths are sorted alphabetically.
directoryPath
- type:
String
The relative or absolute path of the target directory.
options.depth
- type:
Number
The maximum search depth of the directory tree.
options.filter
- type:
RegExporFunction
A regular expression instance against which to test each file path or a callback function to pass to the Array.prototype.filter method. The filter option is used on the final array and matching paths are included in the result.
options.reject
- type:
RegExporFunction
Similar to filter except matched paths are excluded from the result. Reject is used on each recursive call and, as such, is more efficient than filter as it will skip recursive calls on matching paths.
options.relative
type:
Booleandefault:
false
Set to true to return a list of relative paths.
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago