Created
July 24, 2014 15:04
-
-
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'
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'), | |
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