Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
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 |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
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 ... [show rest of quote] -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
In reply to this post by Kline, David D.
Dave,
May I suggest a macro that first creates a file list from the desired directory by use of arrayOfNames = getFileList( directoryPath ); Then loop through the array and test for the desired "substring" by idx = indexOf( arrayOfNames[i], substring ); If ( idx >= 0 ) then the substring is part off the name = arrayOfNames[i] and you may use it for opening the file. HTH Herbie ________________________________________ On 03.05.13 19:01, Kline, David D. 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 > ... [show rest of quote] -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
In reply to this post by Glen MacDonald-2
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 > ... [show rest of quote] 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 |
Free forum by Nabble | Disable Popup Ads | Edit this page |