Created
February 21, 2017 00:59
-
-
Save SgiobairOg/37b7ebcfb0965be8896bda7613f04eb6 to your computer and use it in GitHub Desktop.
Saw IV
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 = require('mz/fs'); | |
const co = require('co'); | |
/* CSV is BULLSHIT | |
* Write a function that takes a directory and 'fixes' csv files by switching them to .txt | |
* Extra bonus if it recurses into the subdirectory | |
*/ | |
const hateMyBoss = function ( path ) { | |
fs.readdir( path, function ( err, items ) { | |
items.forEach( function(item) { | |
let handle = path + '/' + item; | |
if (fs.statSync(handle).isDirectory()) { | |
hateMyBoss( handle ); | |
} else { | |
if (/\.csv$/.test(handle)) { | |
console.log(handle); | |
console.log(handle.substr(0, handle.lastIndexOf(".")) + ".txt"); | |
fs.rename(handle, handle.substr(0, handle.lastIndexOf(".")) + ".txt"); | |
} | |
} | |
}); | |
}); | |
return; | |
} | |
if (process.argv.length <= 2) { | |
console.log("Usage: " + __filename + " path/to/directory"); | |
process.exit(-1); | |
} | |
let path = process.argv[2]; | |
hateMyBoss(path); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment