Skip to content

Instantly share code, notes, and snippets.

@tsbits
Created April 13, 2015 09:20
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 tsbits/3c84242af3782480c3ce to your computer and use it in GitHub Desktop.
Save tsbits/3c84242af3782480c3ce to your computer and use it in GitHub Desktop.
Renaming an image sequence with nodeJS & fs
var fs = require('fs');
//That function list all the files in the directory.
//Loop all the file in the folder
//If the current object is a folder -> ignore it
//Else if the file name index of 'mairie' (the original image sequence file was named "mairie"+n, where n started at 200)
//rename it in "mairie"+i, to get an image sequence that begin at 0 and not 200
function getFiles (dir, files_){
files_ = files_ || [];
var files = fs.readdirSync(dir);
for (var i in files){
var name = dir + '/' + files[i];
if( !fs.statSync(name).isDirectory() ){
if( name.indexOf('mairie') > -1 ){
files_.push(name);
fs.renameSync( name, dir + '/' + 'mairie' + i + '.png' );
}
}
}
return files_;
}
console.log( getFiles('.') );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment