Skip to content

Instantly share code, notes, and snippets.

@icyflame
Created October 7, 2016 09:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icyflame/0fbcb79684e422759281877ceb70af9b to your computer and use it in GitHub Desktop.
Save icyflame/0fbcb79684e422759281877ceb70af9b to your computer and use it in GitHub Desktop.
function findZip(dir, callback) {
var fs = require('fs');
var fileList = fs.readdirSync(dir);
var candidates = [];
for(i in fileList) {
if (fileList[i].match(/.zip$/)) {
candidates.push(fileList[i]);
}
}
if (candidates.length == 1) {
console.log("Found one other ZIP file: " + candidates[0]);
console.log("Do you want to upload this zip file? (y/n): ");
var stdin = process.stdin;
stdin.resume();
stdin.once("data", function(data) {
if (data.toString().localeCompare("y")) {
var path = require('path');
callback(null, path.join(dir, candidates[0]));
} else {
callback(new Error("User rejected uploading of another zip in place of www.zip"));
}
});
}
}
findZip("/code/OpenBrews", function(err, filepath) {
if (err) {
console.error(err);
process.exit(1);
} else {
console.log("Okay, will upload " + filepath);
process.exit(0);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment