Created
February 21, 2017 00:31
-
-
Save lynnaloo/2f042740b01e4dc810c2f5d924c5b38e to your computer and use it in GitHub Desktop.
Steve's Gist
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
var fs = require('fs'); | |
if (process.argv.length <= 2) { | |
console.log("Usage: " + __filename + " path/to/directory"); | |
process.exit(-1); | |
} | |
var path = process.argv[2]; | |
var fs = require('fs'); | |
var newresults = []; | |
var walk = function(dir, done) { | |
var results = []; | |
fs.readdir(dir, function(err, list) { | |
if (err) return done(err); | |
var i = 0; | |
(function next() { | |
var file = list[i++]; | |
if (!file) return done(null, results); | |
var change=false; | |
if(file.split(".")[1]=='csv'){ | |
change=true; | |
} | |
file = dir + '/' + file; | |
if (change){ | |
fs.rename(file, file.split(".")[0]+".txt", function (err) { | |
if (err) throw err; | |
console.log('renamed complete'); | |
}); | |
} | |
fs.stat(file, function(err, stat) { | |
if (stat && stat.isDirectory()) { | |
walk(file, function(err, res) { | |
results = results.concat(res); | |
next(); | |
}); | |
} else { | |
results.push(file); | |
next(); | |
} | |
}); | |
})(); | |
}); | |
}; | |
console.log(path); | |
walk(path, function(err, results) { | |
if (err) throw err; | |
console.log(results); | |
}); | |
//server.listen(8000); | |
//console.log("loaded!"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment