Find Files
Path:
/src/method/find.coffee
compiled to/lib/method/find.js
This is a powerfull method to search for files on the local filesystem. It works recursively with multiple checks and to get a file list as quick as possible.
To define which files to select you may use the following options::
filter
-Array<Object>|Object
Filter Rulesdereference
-Boolean
dereference symbolic links and go into themìgnoreErrors
-Boolean
go on and ignore IO errorsparallel
-Integer
number of maximum parallel calls in asynchronous run (defaults to half of open files limit per process on the system)
To not completely exhaust the system or the allowed open files per process use the parallel limit but because this runs recursively the square root of the given value is used for the first and less for each other level of depth.
Example:
CoffeeScript Code fs = require 'alinex-fs'
fs.find '/tmp/some/directory',
filter:
include: '*.jpg'
, (err, list) ->
return console.error err if err
console.log "Found " + list.length + " images."
# do something with list
find()
Usage:
find(search, options, cb)
- Parameter
-
search
-String
source path to be searched inoptions
-Object
optional specifications for check defining which files to listcb
-function(Error, Array)
optional callback which is called after done with anÈrror
or the complete list of files found asÀrray
findSync()
Usage:
findSync(search, options)
- Parameter
-
search
-String
source path to be searched inoptions
-Object
optional specifications for check defining which files to list
- Return
Array
complete list of files found- Throws
-
Error
if anything out of order happened
Debugging
This module uses thedebug module so you may anytime call your app with
the environment setting DEBUG=fs:find
for the output of this method only.
fs:find check test/temp +0ms
fs:filter skip test/temp because path not included +5ms
fs:filter test/temp SKIP +1ms
fs:find going deeper into test/temp directory +40ms
fs:find check test/temp/dir1 +1ms
fs:find check test/temp/dir2 +0ms
fs:find check test/temp/dir3 +0ms
fs:find check test/temp/file1 +0ms
fs:find check test/temp/file2 +0ms
fs:filter test/temp/dir1 OK +1ms
fs:filter skip dir2 because path not included +0ms
fs:filter test/temp/dir2 SKIP +0ms
fs:filter skip dir3 because path not included +0ms
fs:filter test/temp/dir3 SKIP +0ms
fs:filter test/temp/file1 OK +0ms
fs:filter skip file2 because path not included +0ms
fs:filter test/temp/file2 SKIP +0ms
fs:find going deeper into test/temp/dir1 directory +0ms
fs:find going deeper into test/temp/dir2 directory +0ms
fs:find check test/temp/dir1/file11 +1ms
fs:filter test/temp/dir1/file11 OK +0ms