Skip to content

Instantly share code, notes, and snippets.

@gabrielstuff
Created January 17, 2015 02:29
Show Gist options
  • Save gabrielstuff/32548ecc2ef953b65bd3 to your computer and use it in GitHub Desktop.
Save gabrielstuff/32548ecc2ef953b65bd3 to your computer and use it in GitHub Desktop.
Rename a file by incrementing its number
var fs = require('fs'),
schedule = require('node-schedule'),
currentfilename = '/Users/gabrielstuff/Desktop/default/iehg',
newFilename = '/Users/gabrielstuff/Desktop/default/video',
extension = 'mp4',
number = 0;
function rename() {
fs.rename(currentfilename+'.' + extension, newFilename + '_' + number + '.' + extension, function(err) {
if (err) {
console.log('error moving: ' + err);
}
currentfilename = newFilename + '_' + number;
number++;
});
}
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
// Just to keep the console open
rl.question("What do you think of node.js? ", function(answer) {
console.log("Thank you for your valuable feedback:", answer);
rl.close();
});
setInterval(function(){
rename();
}, 120000);
rename();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment