Flexible and fluent interface for searching the file system
npm install --save filehound
- Flexible search filters
- Simple fluent interface
- Ability to combine search results from multiple queries
- Supports promises and callbacks
The example below prints all of the files in a directory that have the .json
file extension:
const FileHound = require('filehound');
const files = FileHound.create()
.paths('/some/dir')
.ext('json')
.find();
files.then(console.log);
Find all the files that start with dev
:
const files = FileHound.create()
.paths('/etc/pki/')
.match('dev*')
.find();
Find all of the files in a directory that are larger than 1024 bytes:
const files = FileHound.create()
.paths('/some/dir')
.size('>1024')
.find();
Find all the .txt
files that are larger than 1024 bytes and start with note
:
const files = FileHound.create()
.paths('/etc/pki/')
.match('note*')
.ext('txt')
.size('>1024')
.find();
Find all of the files that don't have the .json
extension:
const files = FileHound.create()
.ext('json')
.not()
.find();
Find all the files that are either over 1K or have the .json
file extension:
const filesOverOneK = FileHound.create()
.paths('/some/dir')
.size('>1024')
.find();
const jsonFiles = FileHound.create()
.paths('/some/dir')
.ext('json')
.find();
const files = FileHound.any(filesOverOneK, jsonFiles);
Find all empty text files in /tmp:
FileHound.create()
.paths('/tmp')
.ext('txt')
.isEmpty()
.find((err, emptyTextFiles) => {
console.log(emptyTextFiles);
});
Returns a FileHound instance.
- Accepts one or more instances of FileHound. Will unpack an array.
Returns a Promise of all matches. If the Promise fulfills, the fulfillment value is an array of all matching files.
- Accepts one or more instances of FileHound to negate. Will unpack an array.
- If the Promise fulfills, the fulfillment value is an array of negated matches
Directories to search. Accepts one or more directories or a reference to an array of directories
- path - array of directories
- Returns a FileHound instance
- extension - file extension to filter by
- Returns a FileHound instance
- glob - file glob (as string) to filter by
- Returns a FileHound instance
- sizeExpression - accepts a positive integer representing the file size in bytes. Optionally, can be prefixed with a comparison operator, including <, >, ==, <=, >=
- Returns a FileHound instance
- Returns a FileHound instance
- fn(file) - accepts a custom file matching predicate
- Returns a FileHound instance
- Returns a Promise of all matches. If the Promise fulfills, the fulfillment value is an array of all matching files.
npm test
To generate a test coverage report:
npm run coverage