Created
April 13, 2015 09:20
-
-
Save tsbits/3c84242af3782480c3ce to your computer and use it in GitHub Desktop.
Renaming an image sequence with nodeJS & fs
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'); | |
//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