Skip to content

Instantly share code, notes, and snippets.

@muratcakmak
Created December 25, 2022 09:37
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 muratcakmak/4a03ee7fdc012c7b36757d7206275b25 to your computer and use it in GitHub Desktop.
Save muratcakmak/4a03ee7fdc012c7b36757d7206275b25 to your computer and use it in GitHub Desktop.
import fs from "fs";
(async () => {
let files = [];
let lineCount = 0;
const directoryPath = ".";
const fileType = "csv";
try {
const fileNames = fs.readdirSync(directoryPath);
fileNames.forEach((fileName) => {
const lastThree = fileName.substring(fileName.length - fileType.length);
if (lastThree === fileType) {
files.push(fileName);
}
});
} catch (e) {
console.error({ e });
}
console.log({ files });
files.forEach((filePath) => {
const csvString = fs.readFileSync(filePath, "utf8");
const lines = csvString.split("\n");
lineCount += lines.length;
});
console.log(`Total line count: ${lineCount}`);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment