Skip to content

Instantly share code, notes, and snippets.

@AdmiralPotato
Created July 24, 2014 15:04
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 AdmiralPotato/583ccd4720fc79f8780e to your computer and use it in GitHub Desktop.
Save AdmiralPotato/583ccd4720fc79f8780e to your computer and use it in GitHub Desktop.
A quick node tool to copy a sequence of images from one folder to another, in reverse order. '0001.exr' -> '0048.exr', '0048.exr' -> '0001.exr'
var fs = require('fs'),
path = require('path'),
inputPath = '4',
outputPath = '4-reversed',
suffix = 'exr',
startFrame = 1,
endFrame = 48,
paddingZeroes = 4,
pad = function (num, size) {
var s = num+"";
while (s.length < size) s = "0" + s;
return s;
},
listProcessor = function(err, fileNameList){
if(err){throw err;}
fileNameList.forEach(function (fileName) {
var split = fileName.split('.'),
newName = pad(startFrame + endFrame - parseInt(split[0], 10), 4) + '.' + split[1];
if(split[1] !== suffix){
console.log(fileName + ' was not the correct type, so it was not processed.');
}
fs.createReadStream(
path.join(inputPath, fileName)
).pipe(
fs.createWriteStream(
path.join(outputPath, newName)
).on(
'finish',
function() {
console.log(fileName, '->', newName);
}
)
);
});
};
fs.readdir(inputPath, listProcessor);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment