Skip to content

Instantly share code, notes, and snippets.

@nojvek
Created November 26, 2018 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nojvek/b03f01f0d05d934de6f897ff465605ff to your computer and use it in GitHub Desktop.
Save nojvek/b03f01f0d05d934de6f897ff465605ff to your computer and use it in GitHub Desktop.
Count lines by file extension and path and output csv ready to be sql-analyzed
/* eslint-env node */
const fs = require(`fs`);
const path = require(`path`);
const filePaths = fs.readFileSync(`${__dirname}/file_list.txt`, `utf-8`).trim().split(`\n`);
console.log(`Total files`, filePaths.length);
for (let i = 0, len = filePaths.length; i < len; ++i) {
const filePath = filePaths[i];
let lines = null;
try {
lines = fs.readFileSync(filePath, `utf-8`).split(`\n`).filter(l => /\w/.test(l));
} catch (e) {}
if (lines) {
console.log(`${filePath}, ${path.extname(filePath)}, ${lines.length}`);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment