mirror of
https://github.com/SileNce5k/jscripts.git
synced 2025-04-19 11:08:24 +02:00
Add cleanuptxtfile.js
For cleaning up text file that has been created by copying foobar2k songs and pasting into notepad. (basically just removing '[]' and everything in between :))
This commit is contained in:
parent
7826ad2e50
commit
8cf3c29008
1 changed files with 44 additions and 0 deletions
44
cleanuptxtfile.js
Normal file
44
cleanuptxtfile.js
Normal file
|
@ -0,0 +1,44 @@
|
|||
// Clean up txt file that is created by copying foobar2k songs and pasting into notepad. (Basically just removing '[]' and everything in between :))
|
||||
// First arg is path to file
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
|
||||
function argHandler(args){
|
||||
let pathToTextFile = "";
|
||||
switch (args[2]) {
|
||||
case "--help":
|
||||
case "-h":
|
||||
case undefined:
|
||||
printHelp();
|
||||
break;
|
||||
default:
|
||||
pathToTextFile = args[2];
|
||||
break;
|
||||
}
|
||||
return pathToTextFile;
|
||||
}
|
||||
|
||||
function printHelp(){
|
||||
const helpText = `Usage:\n\tnode cleanuptxtfile.js <path_to_text_file>\n`;
|
||||
process.stdout.write(helpText);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
function fileNotFound(pathToTextFile) {
|
||||
console.log(`FILE NOT FOUND: ${pathToTextFile}\n`)
|
||||
process.exit(404)
|
||||
}
|
||||
|
||||
function cleanFile(pathToTextFile) {
|
||||
let file = fs.readFileSync(pathToTextFile).toString();
|
||||
const regex = /(\[)(.*)(\])/gm
|
||||
file = file.replace(regex, "");
|
||||
fs.writeFileSync(`CLEANED.txt`, file);
|
||||
}
|
||||
|
||||
let pathToTextFile = argHandler(process.argv);
|
||||
|
||||
fs.existsSync(pathToTextFile) ? cleanFile(pathToTextFile) : fileNotFound(pathToTextFile)
|
||||
|
||||
console.log(process.argv[2])
|
Loading…
Add table
Reference in a new issue