From 78a98e70ccbaeca5d1361250b949e91fc39dd6d5 Mon Sep 17 00:00:00 2001 From: SileNce5k Date: Thu, 18 Aug 2022 19:34:20 +0200 Subject: [PATCH] Improve tings n shit --- cleanuptxtfile.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cleanuptxtfile.js b/cleanuptxtfile.js index 015dd0d..6fc4eaa 100644 --- a/cleanuptxtfile.js +++ b/cleanuptxtfile.js @@ -2,6 +2,7 @@ // First arg is path to file const fs = require('fs'); +const path = require('path'); function argHandler(args){ @@ -34,11 +35,11 @@ function cleanFile(pathToTextFile) { let file = fs.readFileSync(pathToTextFile).toString(); const regex = /(\[)(.*)(\])/gm file = file.replace(regex, ""); - fs.writeFileSync(`CLEANED.txt`, file); + let newPath = `CLEANED_${path.basename(pathToTextFile)}` + fs.writeFileSync(newPath, file); + console.log(`\nWrote new file to ${newPath}`) } let pathToTextFile = argHandler(process.argv); -fs.existsSync(pathToTextFile) ? cleanFile(pathToTextFile) : fileNotFound(pathToTextFile) - -console.log(process.argv[2]) \ No newline at end of file +fs.existsSync(pathToTextFile) ? cleanFile(pathToTextFile) : fileNotFound(pathToTextFile) \ No newline at end of file