Skip to content

Instantly share code, notes, and snippets.

@Jpunt
Created December 30, 2013 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jpunt/8187667 to your computer and use it in GitHub Desktop.
Save Jpunt/8187667 to your computer and use it in GitHub Desktop.
Little node-script to find *.iso's in my collection and move them to temporary directories to either encode, redownload or delete them later on.
var glob = require('glob');
var path = require('path');
var cli = require('cline')();
var fs = require('fs');
var fromBase = '/Volumes/Video/Movies';
var toDownload = '/Volumes/Video/TODO/Download';
var toEncode = '/Volumes/Video/TODO/Encode';
var toDelete = '/Volumes/Video/TODO/Delete';
var files;
var i = 0;
glob(fromBase + '/**/*.iso', { nocase:true}, function(er,result){
files = result;
if(files.length > 0) {
handleFile(files[0]);
} else {
console.log("no iso's found");
process.kill();
}
});
function handleFile(file) {
console.log('----');
console.log(file);
cli.prompt("1) Download\n2) Encode\n3) Delete\n", function (input) {
var from = path.dirname(file);
var to;
switch(input) {
case '1': to = from.replace(fromBase, toDownload); break;
case '2': to = from.replace(fromBase, toEncode); break;
case '3': to = from.replace(fromBase, toDelete); break;
}
fs.rename(from, to, function() {
i ++;
if(i < files.length) {
handleFile(files[i]);
} else {
console.log('all done');
process.kill();
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment