Last active
December 27, 2022 15:14
-
-
Save muratcakmak/83d46f0542057f0fd4334269a1f3564c to your computer and use it in GitHub Desktop.
We can make this file beautiful and searchable if this error is corrected: Illegal quoting in line 1.
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
const fs = reqiure("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 }); | |
fs.writeFile("merged.csv", "", function(err) { | |
if (err) throw err; | |
console.log("File is created successfully."); | |
}); | |
files.forEach((filePath) => { | |
const csvString = fs.readFileSync(filePath, "utf8"); | |
fs.appendFile("merged.csv", csvString, (err) => { | |
if (err) throw err; | |
console.log("File is merged successfully."); | |
}); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment