-
Notifications
You must be signed in to change notification settings - Fork 744
Cannot recursively list all *.js files #162
Copy link
Copy link
Closed
Description
I think I'm either missing something... It seems like you can pass an -R flag to the ls() command and it should search recursively, but if I specify a file filter (*.js only) then it seems to ignore the recursive flag...
Steps to reproduce:
'use strict';
var shell = require('shelljs');
console.log('1. Finds all *.html files, regardless of directory depth.');
shell.find('./').filter(function (file) {
return file.match(/\.html?$/i);
}).forEach(function (file) {
console.log(file);
});
console.log('\n2. Finds all *.js files in the current directory only.');
shell.ls('*.js').forEach(function (file) {
console.log(file);
});
console.log('\n3. Finds all *.js files in the nested directories.');
shell.ls('-R', ['*.js']).forEach(function (file) {
console.log(file);
});Output:
1. Finds all *.html files, regardless of directory depth.
node_modules/eslint/node_modules/doctrine/test/test.html
node_modules/eslint/node_modules/js-yaml/demo/index.html
node_modules/eslint/node_modules/js-yaml/node_modules/argparse/node_modules/underscore/index.html
node_modules/eslint/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/test/test.html
node_modules/eslint/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/test/test_standalone.html
node_modules/eslint/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/test/test_underscore/index.html
2. Finds all *.js files in the current directory only.
index.js
3. Finds all *.js files in the nested directories.
index.jsWorkaround:
Use find() and do your own file filtering using the Array.filter() method.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels