-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathwalk.js
More file actions
31 lines (29 loc) · 745 Bytes
/
walk.js
File metadata and controls
31 lines (29 loc) · 745 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const fs = require('fs');
module.exports = function walk(dir) {
let results = [];
/**
* If the param is a directory we can return the file
*/
if (dir.includes('md')) {
return [dir];
}
const list = fs.readdirSync(dir);
list.forEach(function (file) {
file = dir + '/' + file;
const stat = fs.statSync(file);
if (stat && stat.isDirectory()) {
/* Recurse into a subdirectory */
results = results.concat(walk(file));
} else {
/* Is a file */
results.push(file);
}
});
return results;
};