Trouble using "endsWith" statements

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Trouble using "endsWith" statements

Franklin
Hello!
I recently started writing macros and have been struggling with this one
problem for about a week. I have a directory containing two versions of each
file, one version in TIFF form and the other in CZI form. I want to open all
the CZI files, but the program I wrote opens everything. There's a simple
fix but I'm stumped. Assistance would be greatly appreciated.

dir1 = getDirectory("Select Input Directory");
list = getFileList(dir1);
for (i=0; i<list.length; i++)
        {
        showProgress(i+1, list.length);
        filename = dir1 + list[i];
                if(endsWith(filename,"czi")){
                open(filename);
                run("Z Project...", "projection=[Max Intensity]");
                saveAs("TIFF", dir1+list[i]+"Max");
                close();
        }



--
Sent from: http://imagej.1557.x6.nabble.com/

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Trouble using "endsWith" statements

Herbie
Greetings,

I don't think that plain ImageJ is able to open CZI-files. I think you
need to use the "Bio-Formats"-importer to do this.

That being said, I doubt what you've stated that "[...] the program I
wrote opens everything."

In principle your macro codes seems ok, but you should write:

saveAs( "TIFF", filename+"_Max.tif")

and

add the missing last curly brace at the end.

Regards

Herbie

::::::::::::::::::::::::::::::::::::::
Am 08.03.20 um 15:08 schrieb Franklin:

> dir1 = getDirectory("Select Input Directory");
> list = getFileList(dir1);
> for (i=0; i<list.length; i++)
> {
> showProgress(i+1, list.length);
> filename = dir1 + list[i];
> if(endsWith(filename,"czi")){
> open(filename);
> run("Z Project...", "projection=[Max Intensity]");
> saveAs("TIFF", dir1+list[i]+"Max");
> close();
>          }

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Trouble using "endsWith" statements

CARL Philippe (LBP)
Dear Franklin,
I would as well write:
        if(endsWith(list[i],"czi")){
                filename = dir1 + list[i];

instead of:
        filename = dir1 + list[i];
        if(endsWith(filename,"czi")){

Have a nice end of week-end,
Philippe

Philippe CARL
Laboratoire de Bioimagerie et Pathologies
UMR 7021 CNRS - Université de Strasbourg
Faculté de Pharmacie
74 route du Rhin
67401 ILLKIRCH
Tel : +33(0)3 68 85 42 89

----- Le 8 Mar 20, à 16:03, l16 [hidden email] a écrit :

Greetings,

I don't think that plain ImageJ is able to open CZI-files. I think you
need to use the "Bio-Formats"-importer to do this.

That being said, I doubt what you've stated that "[...] the program I
wrote opens everything."

In principle your macro codes seems ok, but you should write:

saveAs( "TIFF", filename+"_Max.tif")

and

add the missing last curly brace at the end.

Regards

Herbie

::::::::::::::::::::::::::::::::::::::
Am 08.03.20 um 15:08 schrieb Franklin:

> dir1 = getDirectory("Select Input Directory");
> list = getFileList(dir1);
> for (i=0; i<list.length; i++)
> {
> showProgress(i+1, list.length);
> filename = dir1 + list[i];
> if(endsWith(filename,"czi")){
> open(filename);
> run("Z Project...", "projection=[Max Intensity]");
> saveAs("TIFF", dir1+list[i]+"Max");
> close();
>          }

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

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Trouble using "endsWith" statements

Stein Rørvik
The problem is that you are missing the second curly closing bracket. The compiler interprets this as the endswith statement block being empty, placing the open line outside the intended block. So all you need is to place a closing bracket at the end.

Sendt fra min iPhone

> 8. mar. 2020 kl. 16:25 skrev CARL Philippe (LBP) <[hidden email]>:
>
> Dear Franklin,
> I would as well write:
>        if(endsWith(list[i],"czi")){
>                filename = dir1 + list[i];
>
> instead of:
>        filename = dir1 + list[i];
>        if(endsWith(filename,"czi")){
>
> Have a nice end of week-end,
> Philippe
>
> Philippe CARL
> Laboratoire de Bioimagerie et Pathologies
> UMR 7021 CNRS - Université de Strasbourg
> Faculté de Pharmacie
> 74 route du Rhin
> 67401 ILLKIRCH
> Tel : +33(0)3 68 85 42 89
>
> ----- Le 8 Mar 20, à 16:03, l16 [hidden email] a écrit :
>
> Greetings,
>
> I don't think that plain ImageJ is able to open CZI-files. I think you
> need to use the "Bio-Formats"-importer to do this.
>
> That being said, I doubt what you've stated that "[...] the program I
> wrote opens everything."
>
> In principle your macro codes seems ok, but you should write:
>
> saveAs( "TIFF", filename+"_Max.tif")
>
> and
>
> add the missing last curly brace at the end.
>
> Regards
>
> Herbie
>
> ::::::::::::::::::::::::::::::::::::::
>> Am 08.03.20 um 15:08 schrieb Franklin:
>> dir1 = getDirectory("Select Input Directory");
>> list = getFileList(dir1);
>> for (i=0; i<list.length; i++)
>>    {
>>    showProgress(i+1, list.length);
>>    filename = dir1 + list[i];
>>        if(endsWith(filename,"czi")){
>>        open(filename);
>>        run("Z Project...", "projection=[Max Intensity]");
>>        saveAs("TIFF", dir1+list[i]+"Max");
>>        close();
>>         }
>
> --
> ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&amp;data=02%7C01%7Cstein.rorvik%40sintef.no%7Ce1633929dc714c6f6e4108d7c374e666%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C1%7C637192779171299197&amp;sdata=%2Fr8GDIhJ%2B6m7byT5tBSwr%2FzCRNAyKvwX2VXX5fQa8Ug%3D&amp;reserved=0
>
> --
> ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&amp;data=02%7C01%7Cstein.rorvik%40sintef.no%7Ce1633929dc714c6f6e4108d7c374e666%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C1%7C637192779171299197&amp;sdata=%2Fr8GDIhJ%2B6m7byT5tBSwr%2FzCRNAyKvwX2VXX5fQa8Ug%3D&amp;reserved=0

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