Exercise: Recursive Find
Practice how to write a function that returns the list of the files by searching in the directory and subdirectories that contain the given keyword.
We'll cover the following...
Problem statement
Write a recursiveFind()
named callback-style function that takes a path to a directory in the local filesystem and a keyword, as per the following signature:
function recursiveFind(dir, keyword, cb) { /* ... */ }
The function should find all the text files within the given directory that contain the given keyword in the file contents. The list of matching files should be returned using the callback when the search is completed. If no matching file is found, the callback should be invoked with an empty array. As an example test case, if you have the files foo.txt
, bar.txt
, and baz.txt
in myDir
and the keyword batman
is contained in the files foo.txt
and baz.txt
, you should be able to run ...