Login  Register

Re: find distinct subfolder

Posted by Rainer M. Engel on Jun 11, 2015; 10:59am
URL: http://imagej.273.s1.nabble.com/find-distinct-subfolder-tp5013112p5013116.html

Hey Thomas,

maybe you want to do this in some separate steps.

1) loop through your folder structure and list/store all found folders

2) filter the results of the first step for your ".*test_folder.*"
with the built in "endsWith" or "matches" function and store these
results in a new list or array.

3) work on the resulting list/array from step 2 and applying your
desired processing.


Maybe this helps you out somehow..
Rainer


Am 11.06.2015 um 08:42 schrieb Tom Pot:

> Hi together,
>  
> I have a macro that loops through folders and subfolders to process images. The problem I encountered is that the macro should only process the images in a subfolder named e.g. test_folder. Afterwards it should screen the next folder and subfolders for the next 'test_folder'.
>  
> I use the following code to loop through folders and subfolders:
>  
> dir = getDirectory("Select Subjects Directory");
>     setBatchMode(true);
>     count = 0;
>     countFiles(dir);
>     n = 0;
>     processFiles(dir);
>     //print(count+" files processed");
>     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) {
>        list = getFileList(dir);
>        for (i=0; i<list.length; i++) {
>            if (endsWith(list[i], "/"))
>                processFiles(""+dir+list[i]);
>                
>          isDirectory(newdir);
>            else {
>               showProgress(n++, count);
>               path = dir+list[i];
>               calculate_first(path);            // process function 1
>               calculate_second(path);       // process function 2
>            }
>        }
>    }
>  
> Does anybody has an idea how to search a distinct subfolder within my subjects dir ?
>  
> I´m very thankful for any suggestions,
> Thomas
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html