files-path
JS Library to List Files in a Folder List
Super simple to use
files-path is designed to be the simplest way possible to list files in a path.
var fp = ;var files = fp; console;
console output:
Table of contents
Methods
See: Options
- Get files list synchronous
-
var files = require('files-path').sync(options);
- Get files list asynchronous with callback
-
require('files-path').async(options, callback(err, files));
- Get files list asynchronous with Promise
-
require('files-path').async(options).then(files).catch(err);
- Require lib with default options and get files list synchronous
-
var files = require('files-path')(defaultOptions).sync(options);
- Require lib with default options and get files list asynchronous with callback
-
require('files-path')(defaultOptions).async(options, callback(err, files));
- Require lib with default options and get files list asynchronous with Promise
-
require('files-path')(defaultOptions).async(options).then(files).catch(err);
Options
- basePath
-
Default: . (current folder)
Initial folder search
The files on this path will not be returned
./my/relative/initial/path
- useBasePath
-
Default: false
The files distributed on this path will be listed
The files on this path will not be returned
./my/relative/initial/path
- filters
-
Default: undefined
If you add at least one filter, only the files that match this filters will be returned
Note: If no filter is informed, all files are returned
Simple string
filters: ["*.txt", "*.js"]
Simple regex
filters: [ /^file.*m\.(txt|js)$/gi ]
Simple string with callback
filters: [ { pattern: "file*.txt", callback: function (file) {console.log(file.fullName)} ]
Simple regex with callback
filters: [ { pattern: /^file.*m\.(txt|js)$/gi, callback: function (file) {console.log(file.fullName)} ]
- verbose
-
Default: false
Show logs on console - verboseFilters
-
Default: false
Depend of verbose:true
Filter logs.
Samples:
verboseFilters:['file-name.js']
verboseFilters:[/.*test\d+.*/g]
verboseFilters:['contained text', /.*\d{10}.*/g] - maxDeep
-
Default: 50
Maximum number of folders to be scanned
Full Samples
With this folder structure:
♦
└┄ ▼ tests
└┄ ▼ documents
├┄ ▼ dir-a
│ └┄ • file-dir-a.txt
├┄ ▼ dir-b
│ ├┄ ▼ dir-x
│ │ ├┄ ▼ dir-a
│ │ │ └┄ • file-dir-a.txt
│ │ ├┄ • 1file-dir-x.js
│ │ └┄ • 2file-dir-x.txt
│ └┄ • file-dir-b.txt
└┄ • basePath.txt
Basic
var fp = ;var files = fp;console;
Use basePath + Simple Filters (string, regex and callback)
var fp = ;fp;
filter2: tests\documents\basePath.txt
filter1: 1file-dir-x.js
Use default options
var fp = basePath: 'tests/documents';var exec1 = fp;var exec2 = fp;console;console;console;
--
Basic Asyncronous with Callback
var fp = ;var files = fp;
Basic Asyncronous with Promise
var fp = ;var files = fp;
Todo list
- filter by function
- make log.js to become an external npm package
License
Apache-2.0 © Flavio L Sousa ([email protected])