You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
611 B
29 lines
611 B
var fs = require('fs') |
|
var path = require('path') |
|
|
|
module.exports = read |
|
|
|
function read(root, filter, files, prefix) { |
|
prefix = prefix || '' |
|
files = files || [] |
|
filter = filter || noDotFiles |
|
|
|
var dir = path.join(root, prefix) |
|
if (!fs.existsSync(dir)) return files |
|
if (fs.statSync(dir).isDirectory()) |
|
fs.readdirSync(dir) |
|
.filter(function (name, index) { |
|
return filter(name, index, dir) |
|
}) |
|
.forEach(function (name) { |
|
read(root, filter, files, path.join(prefix, name)) |
|
}) |
|
else |
|
files.push(prefix) |
|
|
|
return files |
|
} |
|
|
|
function noDotFiles(x) { |
|
return x[0] !== '.' |
|
}
|
|
|