Created
December 25, 2022 09:37
-
-
Save muratcakmak/4a03ee7fdc012c7b36757d7206275b25 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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