scripts/folder-listing-node/list_extensions.js

39 lines
1.0 KiB
JavaScript
Raw Normal View History

const fs = require('fs');
const path = require('path');
const inputDirNameArg = process.argv[2];
console.log('dossier:', inputDirNameArg)
const extensions = [];
function findFileExtensions(directory) {
function traverseDirectory(dirPath) {
fs.readdir(dirPath, (err, files) => {
if (err) throw err;
files.forEach((file) => {
const filePath = path.join(dirPath, file);
const stat = fs.lstatSync(filePath);
if (stat.isFile()) {
const extension = path.extname(filePath).toLowerCase();
if (!extensions.includes(extension)) {
extensions.push(extension);
}
} else if (stat.isDirectory() && !file.startsWith('.')) {
traverseDirectory(filePath);
console.log(extensions.length, extensions);
}
});
});
}
traverseDirectory(directory);
}
findFileExtensions(inputDirNameArg);