shelljs icon indicating copy to clipboard operation
shelljs copied to clipboard

find() should work like find(1)

Open ritch opened this issue 11 years ago • 1 comments

I expected the following to work... but took a look at the docs and require('shelljs').find quite a bit different than I expected.

Here is what I'm trying to do:

// find all directories in the cwd that have a package.json
var sh = require('shelljs');
var packages = sh.find('*/package.json').map((f) => {
 return path.dirname(f)
}); 

This is obviously not possible with sh.find. You have to do something like

sh.find('.').filter((p) => {
  return path.dirname(p) === cwd
      && path.filename(p) === 'package.json'
});

Would be nice if it supported the same functionality as find(1).

ritch avatar Apr 04 '14 19:04 ritch

The parameter to find is a path, not a pattern. This functionality should be provided via the -name parameter instead, see https://www.gnu.org/software/findutils/manual/html_mono/find.html#Base-Name-Patterns

joshi-sh avatar May 13 '18 02:05 joshi-sh