17 lines
551 B
JavaScript
17 lines
551 B
JavaScript
const path = require("path");
|
|
const fs = require("fs");
|
|
|
|
// Helper function to map recursively over files in a folder and it's subfolders
|
|
module.exports.mapFiles = function mapFiles(startPath, filter, mapFunc) {
|
|
const files = fs.readdirSync(startPath);
|
|
for (let i = 0; i < files.length; i++) {
|
|
const filename = path.join(startPath, files[i]);
|
|
const stat = fs.lstatSync(filename);
|
|
if (stat.isDirectory()) {
|
|
mapFiles(filename, filter, mapFunc);
|
|
} else if (filename.indexOf(filter) >= 0) {
|
|
mapFunc(filename);
|
|
}
|
|
}
|
|
};
|