Well, here is a first attempt. You can copy the text and paste it to the script editor and execute it (F9) AFTER adapting the parameters at the start. Check first with a single file. You can also save it to a file with an extension of js and execute it from the menu.
NOTE: It is possible that the whole file be read in memory with this simple approach, this may or may not work depending on the size of your files and memory. The generation of fiel name may or may not work with your files.
-- bitli
// Extract all images of a multi image fits file,
// Adapt the directories and extension as needed,
// all files in the source directory will be processed and each image
// in each source file will be extracted to the destination directory.
// It is recommended that the destination directory is empty.
// The name will be formed from the name of the source file and ther EXTNAME or,
// if missing, '_part_#'. There is NO check that the generated file name is valid
// or unique. AskONOverwrite will alert you in case of duplicates.
// PROVIDED AS IS - NOT REALLY TESTED, USE AT YOUR OWN RISK.
"use strict";
#include <pjsr/UndoFlag.jsh>
var srcDir = "D:/temp/source";
var dstDir = "D:/temp/dest";
var extension =".fit";
var askOnOverwrite = true;
function copyImages(fileName) {
var sourceFilePath = srcDir + "/" + find.name;
var images = ImageWindow.open( sourceFilePath, "temp", true );
Console.writeln("Loaded " + images.length + " images");
for (var i=0; i<images.length;i++) {
Console.writeln(" Loading image " + i + " of '" + fileName + "'");
var image = images[i];
var keywords = image.keywords;
var extName = "part_" + (i+1);
Console.writeln(" " + keywords.length + " keywords:");
for (var j=0; j<keywords.length; j++) {
if (keywords[j].name === 'EXTNAME') extName = keywords[j].strippedValue;
Console.writeln(" " + keywords[j]);
}
var newFileName = File.extractName(fileName)+"_"+extName+extension;
Console.writeln(" new name: '" + newFileName +"'");
var targetFilePath = dstDir + "/" + newFileName;
// path,queryOptions,allowMessages,strict,verifyOverwrite
image.saveAs(targetFilePath, false, false, false, askOnOverwrite);
image.forceClose();
}
}
var find = new FileFind;
if ( find.begin( srcDir +"/*" + extension) ) {
do
{
if ( find.name != "." && find.name != ".." && find.isFile ) {
Console.writeln("Expanding images in " + find.name);
copyImages(find.name);
}
} while ( find.next() );
}
Console.writeln("Completed");