FileHound

FileHound

new FileHound()

Source:

Methods

(static) accessed(dateExpression)

Filters by file access time

Parameters:
Name Type Description
dateExpression string

date expression

Source:
Returns:

a FileHound instance

Example
import FileHound from 'filehound';

const filehound = FileHound.create();
filehound
  .accessed("< 10 minutes")
  .find()
  .each(console.log);

(static) any()

Returns all matches from one of more FileHound instances

Source:
Returns:

a promise containing all matches. If the Promise fulfils, the fulfilment value is an array of all matching files.

Example
import FileHound from 'filehound';

const filehound = FileHound.any(fh1, fh2);

(static) create()

Static factory method to create an instance of FileHound

Source:
Returns:

FileHound instance

Example
import FileHound from 'filehound';

const filehound = FileHound.create();

(static) modified(dateExpression)

Filters by modifiction time

Parameters:
Name Type Description
dateExpression string

date expression

Source:
Returns:

a FileHound instance

Example
import FileHound from 'filehound';

const filehound = FileHound.create();
filehound
  .modified("< 2 days")
  .find()
  .each(console.log);

addFilter(function)

Parameters:
Name Type Description
function function

custom filter function

Source:
Returns:

a FileHound instance

Example
import FileHound from 'filehound';

const filehound = FileHound.create();
filehound
  .addFilter(customFilter)
  .find()
  .each(console.log);

changed(dateExpression)

Filters change time

Parameters:
Name Type Description
dateExpression string

date expression

Source:
Returns:

a FileHound instance

Example
import FileHound from 'filehound';

const filehound = FileHound.create();
filehound
  .changed("< 10 minutes")
  .find()
  .each(console.log);

depth()

Specify the directory search depth. If set to zero, recursive searching will be disabled

Source:
Returns:

a FileHound instance

Example
import FileHound from 'filehound';

const filehound = FileHound.create();
filehound
  .depth(0)
  .find()
  .each(console.log); // array of files names only in the current directory

directory()

Find sub-directories

Source:
Returns:

a FileHound instance

Example
import FileHound from 'filehound';

const filehound = FileHound.create();
filehound
  .directory()
  .find()
  .each(console.log); // array of matching sub-directories

discard(regex)

Ignores files or sub-directories matching pattern

Parameters:
Name Type Description
regex string | array

regex or array of regex

Source:
Returns:

a FileHound instance

Example
import FileHound from 'filehound';

const filehound = FileHound.create();
filehound
  .discard("*.tmp*")
  .find()
  .each(console.log);

ext(extensions)

Filter on file extension

Parameters:
Name Type Description
extensions string | array

extension or an array of extensions

Source:
Returns:

a FileHound instance

Example
import FileHound from 'filehound';

let filehound = FileHound.create();
filehound
  .ext(".json")
  .find()
  .each(console.log);

// array of extensions to filter by
filehound = FileHound.create();
filehound
  .ext([".json", ".txt"])
  .find()
  .each(console.log);

// supports var args
filehound = FileHound.create();
filehound
  .ext(".json", ".txt")
  .find()
  .each(console.log);

find(function)

Asynchronously executes a file search.

Parameters:
Name Type Description
function function

Optionally accepts a callback function

Source:
Returns:

Returns a Promise of all matches. If the Promise fulfils, the fulfilment value is an array of all matching files

Example
import FileHound from 'filehound';

const filehound = FileHound.create();
filehound
  .find()
  .each(console.log);

// using a callback
filehound
  .find((err, files) => {
     if (err) return console.error(err);

     console.log(files);
  });

findSync()

Synchronously executes a file search.

Source:
Returns:

Returns an array of all matching files

Example
import FileHound from 'filehound';

const filehound = FileHound.create();
const files = filehound.findSync();
console.log(files);

glob(glob)

Filter by a file glob

Parameters:
Name Type Description
glob array

array of globs

Source:
Returns:

a FileHound instance

Example
import FileHound from 'filehound';

const filehound = FileHound.create();
filehound
  .glob(['*tmp*']) // .glob('*tmp*') || .glob('*tmp1*','*tmp2*')
  .find()
  .each(console.log); // array of files names all containing 'tmp'

ignoreHiddenDirectories()

Ignore hidden directories

Source:
Returns:

a FileHound instance

Example
import FileHound from 'filehound';

const filehound = FileHound.create();
filehound
  .ignoreHiddenDirectories()
  .find()
  .each(console.log); // array of files names that are not hidden directories

ignoreHiddenFiles()

Filter to ignore hidden files

Source:
Returns:

a FileHound instance

Example
import FileHound from 'filehound';

const filehound = FileHound.create();
filehound
  .ignoreHiddenFiles()
  .find()
  .each(console.log); // array of files names that are not hidden files

includeFileStats()

Include file stats

Source:
Returns:

a FileHound instance

Example
import FileHound from 'filehound';

const filehound = FileHound.create();
filehound
  .includeFileStats()
  .find()
  .each(console.log); // array of file objects containing `path` and `stats` properties

isEmpty(path)

Filter by zero length files

Parameters:
Name Type Description
path string

path

Source:
Returns:

a FileHound instance

Example
import FileHound from 'filehound';

const filehound = FileHound.create();
filehound
  .size("<10kb")
  .find()
  .each(console.log);

match(glob)

Filter by a file glob

Parameters:
Name Type Description
glob array

array of globs

Source:
Returns:

a FileHound instance

Example
import FileHound from 'filehound';

const filehound = FileHound.create();
filehound
  .match(['*tmp*']) // .match('*tmp*')
  .find()
  .each(console.log); // array of files names all containing 'tmp'

not(glob)

Negates filters

Parameters:
Name Type Description
glob string

file glob

Source:
Returns:

a FileHound instance

Example
import FileHound from 'filehound';

const filehound = FileHound.create();
filehound
  .not()
  .glob("*tmp*")
  .find()
  .each(console.log); // array of files names NOT containing 'tmp'

path(path)

Define the search path

Parameters:
Name Type Description
path string

path

Source:
Returns:

a FileHound instance

Example
import FileHound from 'filehound';

const filehound = FileHound.create();
filehound
  .path("/tmp")
  .find()
  .each(console.log);

paths(path)

Defines the search paths

Parameters:
Name Type Description
path array

array of paths

Source:
Returns:

a FileHound instance

Example
import FileHound from 'filehound';

const filehound = FileHound.create();
filehound
  .paths("/tmp", "/etc") // or ["/tmp", "/etc"]
  .find()
  .each(console.log);

size(sizeExpression)

Filter by file size

Parameters:
Name Type Description
sizeExpression string

a size expression

Source:
Returns:

a FileHound instance

Example
import FileHound from 'filehound';

const filehound = FileHound.create();
filehound
  .size("<10kb")
  .find()
  .each(console.log);

socket()

Find sockets

Source:
Returns:

a FileHound instance

Example
import FileHound from 'filehound';

const filehound = FileHound.create();
filehound
  .socket()
  .find()
  .each(console.log); // array of matching sockets