Re: Output_Files not Saved in Subfolder when the Subfolder contains Super-subfolders
Posted by GP on Mar 30, 2017; 2:52pm
URL: http://imagej.273.s1.nabble.com/Re-Output-Files-not-Saved-in-Subfolder-when-the-Subfolder-contains-Super-subfolders-tp5018423.html
Hie!
I was not able to find the solution to the problem I encountered probably it's some minor mistake:
The following steps have to be performed in the script:
1. Go through the main Directory
2. Find all the Folders present (Ex: 'test1', 'test2', 'test3'.. etc)
3. In each Folder create a Subfolder (let's call it 'Recrop')
4. Get list of images in each Folder
5. Perform image functions on them and Save output images in respective 'Recrop' subfolders.
6. Go to all 'Recrop' subfolders and create two Super-subfolders 'SuperSub1' and 'SuperSub2'
7. Get list of images in 'Recrop'
8. Perform two types of image functions and save them respectively in 'SuperSub1' and 'SuperSub2'
The script works fine when executed till step 5
On executing step 6 'SuperSub1' and 'SuperSub2' are created inside 'Recrop' but the output images from step 5 are not saved in 'Recrop' anymore.
The error might be in the way I am calling the function but I can't figure out how to fix it.
I have attached my macro here:
function processDir(dir) {
listdir = getFileList(dir);
for (j = 0; j < listdir.length; j++) {
outDir = dir+listdir[j]+"Recrop";
File.makeDirectory(outDir);
outpath = outDir+"/";
inDir = dir+listdir[j];
processFolder(inDir); } }
function processFolder(inDir) {
list = getFileList(inDir);
for (i = 0; i < list.length; i++) {
path = inDir+list[i]; //print (path);
processFile(path, outpath); } }
setBatchMode(true);
function processFile(path, outpath){
if (endsWith(path, ".tif")|| endsWith(path, ".TIF")) {
open(path);
Process here...
Title = File.nameWithoutExtension();
saveAs("TIFF", outpath+Title); //doesnt save images to 'outpath'
close(); } } // on executing code after this block
function processFolder(recrop){
listrecrop = getFileList(recrop);
for(k=0; k<listrecrop.length; k++) {
path_re = recrop+listrecrop[k];
if (endsWith(path_re, "/")) {
list_recrop = getFileList(recrop);
for(l=0; l<list_recrop.length; l++) {
inpath_re = path_re+list_recrop[l];
outDir_sub1 = path_re+"/"+"SuperSub1";
File.makeDirectory(outDir_sub1);
outpath_sub1= outDir_sub1+"/";
outDir_sub2 = path_re+"/"+"SuperSub2";
File.makeDirectory(outDir_sub2);
outpath_sub2 = outDir_sub2+"/";
processFile(inpath_re, outpath_sub1, outpath_sub2); } } } }
setBatchMode(true);
function processFile(inpath_re, outpath_sub1, outpath_sub2) {
if (endsWith(inpath_re, ".tif")|| endsWith(inpath_re, ".TIF")) {
open(inpath_re);
Process here..
saveAs("TIFF", outpath_sub1);
close(); }
if (endsWith(inpath_re, ".tif")|| endsWith(inpath_re, ".TIF")) {
open(inpath_re);
Process here..
saveAs("TIFF", outpath_sub2);
close(); } }
Thank you so much,
Best Regards,