1 | var path = require('path');
|
2 | var common = require('./common');
|
3 | var _ls = require('./ls');
|
4 |
|
5 | common.register('find', _find, {});
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | function _find(options, paths) {
|
24 | if (!paths) {
|
25 | common.error('no path specified');
|
26 | } else if (typeof paths === 'string') {
|
27 | paths = [].slice.call(arguments, 1);
|
28 | }
|
29 |
|
30 | var list = [];
|
31 |
|
32 | function pushFile(file) {
|
33 | if (process.platform === 'win32') {
|
34 | file = file.replace(/\\/g, '/');
|
35 | }
|
36 | list.push(file);
|
37 | }
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | paths.forEach(function (file) {
|
43 | var stat;
|
44 | try {
|
45 | stat = common.statFollowLinks(file);
|
46 | } catch (e) {
|
47 | common.error('no such file or directory: ' + file);
|
48 | }
|
49 |
|
50 | pushFile(file);
|
51 |
|
52 | if (stat.isDirectory()) {
|
53 | _ls({ recursive: true, all: true }, file).forEach(function (subfile) {
|
54 | pushFile(path.join(file, subfile));
|
55 | });
|
56 | }
|
57 | });
|
58 |
|
59 | return list;
|
60 | }
|
61 | module.exports = _find;
|