Processing a directory of images using JavaScript and WEKA

Hello,

I am currently struggling in writing a JS macro that can process a directory of images. The following is the macro that I have thus far:

importClass(Packages.ij.io.OpenDialog);
importClass(Packages.ij.IJ);
importClass(Packages.ij.plugin.frame.RoiManager);
importClass(Packages.trainableSegmentation.WekaSegmentation);
importClass(Packages.ij.plugin.frame.ThresholdAdjuster);
importClass(Packages.java.io.File);

var input_dir = IJ.getDirectory("Choose input folder");

var output_dir = IJ.getDirectory("Choose output folder");


od = new OpenDialog("Choose a classifier", null);
folder = od.getDirectory();
file = od.getFileName();
path = folder + file;

processFolder(input_dir, output_dir, path);

function processFolder(input, output, classifier_path) {
	var dir = new java.io.File(input);
	list = dir.listFiles();
	for (i = 0; i < list.length; i++) {
			processFile(input, output, list[i],  classifier_path);
	}
}



function processFile(input, output, file, classifier_path){
	rm = new RoiManager();
	if(path){
		var weka = new WekaSegmentation( file );
		var classifierFile = classifier_path;
		weka.loadClassifier(classifierFile);
		weka.applyClassifier(false);
		result = weka.getClassifiedImage();
		result.show();

		IJ.run("Enhance Contrast", "saturated=0.3");
		IJ.setAutoThreshold(result,"Intermodes");
		IJ.run("Set Measurements...", "area bounding fit limit redirect=None decimal=3");
		IJ.run(result, "Analyze Particles...", "add");
		result.close();
		rm.runCommand(imp,"Show All");
		rm.runCommand(imp,"Measure");
		IJ.saveAs("Results", output + file + "Results.xls");
}
}

As you can see, I am struggling in writing the process folder section of the macro. I know that the processFiles should work fine as I have been using it to process individual files, however, I haven’t been able to figure out how to get the processFolder to work. Thanks!