Login  Register

Re: open file with specific partial name

Posted by Walter O'Dell PhD on May 03, 2013; 5:22pm
URL: http://imagej.273.s1.nabble.com/open-file-with-specific-partial-name-tp5002910p5002913.html

and you want to use >= 1 rather than =1
i.e.
indexOf(list[i],"foes")>=1

actually I would use zero incase your keyword is the start of the filename

indexOf(list[i],"foes")>=0

a value of -1 means that it was not found

On May 3, 2013, at 1:15 PM, Glen MacDonald wrote:

> Dave,
> This may be helpful:
>
> dir=getDirectory("Select the directory");
> list=getFileList(dir);
> for(i=0;i<list.length;i++){
> if(endsWith(list[i],".tif")&&indexOf(list[i],"foes")=1){
> do stuff;
> }
> }
>
> or find the files and concatenate the into an array of chosen files to batch process them:
>
> files=newArray(0);
> dir=getDirectory("Select the directory");
> list=getFileList(dir);
> for(i=0;i<list.length;i++){
> if(endsWith(list[i],".tif")&&indexOf(list[i],"foes")=1){
> files=Array.concat(files,list[i]);
> }
> }
> for(f=1;f<files.length;f++){
> open(files[f]);
> doStuff;
> }
>
>
> also, look at some of the macros on the ImageJ website.
> Regards
> Glen MacDonald
> Core for Communication Research
> Virginia Merrill Bloedel Hearing Research Center
> Cellular Morphology Core
> Center on Human Development and Disability
> Box 357923
> University of Washington
> Seattle, WA 98195-7923  USA
> (206) 616-4156
> [hidden email]
>
>
>
> On May 3, 2013, at 10:01 AM, "Kline, David D." <[hidden email]> wrote:
>
>> Thank you in advance for any help.
>>
>> We are trying to write a macro that opens a file with a particular word/text in the file name. For example if the file is named "dave_fos_40X.tif" how can we have IJ only open the file that contains the word "foes". This is needed because there may be many files in the same folder with a similar name (e.g., "dave_neurons_40X.tif", "dave_glia_40X.tif"). There is usually only one file with the text "foes" in the folder. We have tried using wildcards and renaming the files with no success. There must be a simple way that I am not seeing.
>>
>> Any advice is appreciated.
>>
>> Thanks!
>> Dave
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

Walter O'Dell, PhD
Assistant Professor
Dept. Radiation Oncology
McKnight Brain Inst. Rm LG-177
PO Box 100385
Shands Cancer Center, University of Florida
Gainesville, FL 32610
[hidden email]
352-273-9030
http://odell.radonc.med.ufl.edu




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