Batch Processing Macro & Saving Summary File Within Each Folder

imagej
batch-processing
macro
save

#1

Hello Everyone,

I am attempting to write a script to batch process multiple subfolders within a main folder & to save a summary document holding pixel count data within each subfolder. With the structure below I want to be able to save the summary.txt file within each Subfolder before moving to the next subfolder. I am able to recursively process through all the subfolders but can only export a single summary.txt file at the very end (see code at end of post)- does anyone have an idea of the best way to achieve getting the summary saved in each individual subfolder?

  1. MAIN FOLDER
    Subfolder A
    - img_001
    - img_002
    - img_003
    - img_etc, etc
    Subfolder B
    - img_001
    - img_002
    - img_003
    Subfolder C, etc, etc
    - img_001
    - img_002
    - img_003

Example Code that only saves a single summary:

dir = getDirectory(“Select Directory “);
count = 0;
countFiles(dir);
n = 0;
processFiles(dir, n);
function countFiles(dir) {
list = getFileList(dir);
for (i=0; i<list.length; i++) {
if (endsWith(list[i], “/”))
countFiles(””+dir+list[i]);
else
count++;
}
}

function processFiles(dir, dir2) {
list = getFileList(dir);
for (i=0; i<list.length; i++) {
if (endsWith(list[i], “/”))
processFiles(""+dir+list[i]);
else {
showProgress(n++, count);
path = dir+list[i];
processFile(path);
}
}
}

function processFile(path, dir 2) {
if (endsWith(path, “.jpg”)) {
open(path);
}
}

//IMAGE MANIPULATION & ANALYSIS SCRIPT

selectwindow(“Summary”);
saveAs(“Results”, dir+ “Summary.txt”);
Run(“Close”);
}


#2

Hi there,

Did you fugure it out? I have the same problem.

Ed