Chose only specific file on a folder

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

Chose only specific file on a folder

Pang, Zhengyu (GE Global Research)
Dear all,

I have made a macro to batch process images under a folder. But some
files are not images and I need to ignore these files. How do I do it? I
have used a function of getFileList() to read all files, but how do I
ignore some files ending with".zvd" OR ".archive"? Thanks for your help.

Zhengyu

> g Global Research Center
>
> ______________________________________________________________________
>
>           Zhengyu Pang, Ph.D.
                        Bioanalytics and Protein Science Laboratory
                        Biosciences Global Technology Organization
> One Research Circle, K1 5B37A
> Niskayuna, NY12309
> * [hidden email]
> *(518) 387-4015
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Chose only specific file on a folder

lechristophe
Hi Zhengyu,

Just get all your file names as an array using getFileList() and the
loop on all names to detect the last three characters of the names
using substring(name, 0, LengthOf(name)-4) (I could I've messed the
indexes !). Store that as a new extensions[] array and then put your
whole macro in a for+if loop (loop an all extensions, test if
extension is .tif).

Sorry I don't have a macro at hand that does that to give you the code
directly...

Christophe

On Fri, May 30, 2008 at 6:05 AM, Pang, Zhengyu (GE, Research)
<[hidden email]> wrote:

> Dear all,
>
> I have made a macro to batch process images under a folder. But some
> files are not images and I need to ignore these files. How do I do it? I
> have used a function of getFileList() to read all files, but how do I
> ignore some files ending with".zvd" OR ".archive"? Thanks for your help.
>
> Zhengyu
>
>>               g Global Research Center
>>
>> ______________________________________________________________________
>>
>>           Zhengyu Pang, Ph.D.
>                        Bioanalytics and Protein Science Laboratory
>                        Biosciences Global Technology Organization
>>               One Research Circle, K1 5B37A
>>               Niskayuna, NY12309
>>               * [hidden email]
>>               *(518) 387-4015
>>
>>
>
Reply | Threaded
Open this post in threaded view
|

Re: Chose only specific file on a folder

Michael Schmid
Hi Zhengyu, Christophe,

it very simple: The ImageJ macro language has an "endsWith" function:
http://rsb.info.nih.gov/ij/developer/macro/functions.html#E

if (endsWith(filename, ".jpg")) ...
else if (endsWith(filename, ".txt")) ...
else if (endsWith(filename, ".zvd")) ...

For the loop, see, e.g., the ListFilesRecursively macro
http://rsb.info.nih.gov/ij/macros/ListFilesRecursively.txt

Michael
________________________________________________________________

On 30 May 2008, at 09:07, Christophe Leterrier wrote:

> Hi Zhengyu,
>
> Just get all your file names as an array using getFileList() and the
> loop on all names to detect the last three characters of the names
> using substring(name, 0, LengthOf(name)-4) (I could I've messed the
> indexes !). Store that as a new extensions[] array and then put your
> whole macro in a for+if loop (loop an all extensions, test if
> extension is .tif).
>
> Sorry I don't have a macro at hand that does that to give you the code
> directly...
>
> Christophe
>
> On Fri, May 30, 2008 at 6:05 AM, Pang, Zhengyu (GE, Research)
> <[hidden email]> wrote:
>> Dear all,
>>
>> I have made a macro to batch process images under a folder. But some
>> files are not images and I need to ignore these files. How do I do  
>> it? I
>> have used a function of getFileList() to read all files, but how do I
>> ignore some files ending with".zvd" OR ".archive"? Thanks for your  
>> help.
>>
>> Zhengyu
>>
>>>               g Global Research Center
>>>
>>> ____________________________________________________________________
>>> __
>>>
>>>           Zhengyu Pang, Ph.D.
>>                        Bioanalytics and Protein Science Laboratory
>>                        Biosciences Global Technology Organization
>>>               One Research Circle, K1 5B37A
>>>               Niskayuna, NY12309
>>>               * [hidden email]
>>>               *(518) 387-4015
>>>
>>>
>>
Reply | Threaded
Open this post in threaded view
|

Re: Chose only specific file on a folder

Pang, Zhengyu (GE Global Research)
Michael and Christophe,

Thanks for pointing me to the right direction. endsWith function is what
I need for this purpose.

I previously used a function "contains", but it did not work. Do I need
to include some package to get this function work? I have background for
C language, but not for Java.

Thanks,

Zhengyu

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of
Michael Schmid
Sent: Friday, May 30, 2008 4:45 AM
To: [hidden email]
Subject: Re: Chose only specific file on a folder

Hi Zhengyu, Christophe,

it very simple: The ImageJ macro language has an "endsWith" function:
http://rsb.info.nih.gov/ij/developer/macro/functions.html#E

if (endsWith(filename, ".jpg")) ...
else if (endsWith(filename, ".txt")) ...
else if (endsWith(filename, ".zvd")) ...

For the loop, see, e.g., the ListFilesRecursively macro
http://rsb.info.nih.gov/ij/macros/ListFilesRecursively.txt

Michael
________________________________________________________________

On 30 May 2008, at 09:07, Christophe Leterrier wrote:

> Hi Zhengyu,
>
> Just get all your file names as an array using getFileList() and the
> loop on all names to detect the last three characters of the names
> using substring(name, 0, LengthOf(name)-4) (I could I've messed the
> indexes !). Store that as a new extensions[] array and then put your
> whole macro in a for+if loop (loop an all extensions, test if
> extension is .tif).
>
> Sorry I don't have a macro at hand that does that to give you the code

> directly...
>
> Christophe
>
> On Fri, May 30, 2008 at 6:05 AM, Pang, Zhengyu (GE, Research)
> <[hidden email]> wrote:
>> Dear all,
>>
>> I have made a macro to batch process images under a folder. But some
>> files are not images and I need to ignore these files. How do I do
>> it? I have used a function of getFileList() to read all files, but
>> how do I ignore some files ending with".zvd" OR ".archive"? Thanks
>> for your help.
>>
>> Zhengyu
>>
>>>               g Global Research Center
>>>
>>> ____________________________________________________________________
>>> __
>>>
>>>           Zhengyu Pang, Ph.D.
>>                        Bioanalytics and Protein Science Laboratory
>>                        Biosciences Global Technology Organization
>>>               One Research Circle, K1 5B37A
>>>               Niskayuna, NY12309
>>>               * [hidden email]
>>>               *(518) 387-4015
>>>
>>>
>>
Reply | Threaded
Open this post in threaded view
|

Re: Chose only specific file on a folder

Michael Schmid
Hi Zhengyu,

ImageJ Macros are not Java, but an own macro language that is
similar to Java. See the documentation on the ImageJ Web site.

In the macro language there is no "contains", instead you can use
   indexOf(string, substring)>=0

http://rsb.info.nih.gov/ij/developer/macro/functions.html#indexOf

Michael
________________________________________________________________

On 30 May 2008, at 17:53, Pang, Zhengyu (GE, Research) wrote:

> Michael and Christophe,
>
> Thanks for pointing me to the right direction. endsWith function is  
> what
> I need for this purpose.
>
> I previously used a function "contains", but it did not work. Do I  
> need
> to include some package to get this function work? I have  
> background for
> C language, but not for Java.
>
> Thanks,
>
> Zhengyu
>
> -----Original Message-----
> From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of
> Michael Schmid
> Sent: Friday, May 30, 2008 4:45 AM
> To: [hidden email]
> Subject: Re: Chose only specific file on a folder
>
> Hi Zhengyu, Christophe,
>
> it very simple: The ImageJ macro language has an "endsWith" function:
> http://rsb.info.nih.gov/ij/developer/macro/functions.html#E
>
> if (endsWith(filename, ".jpg")) ...
> else if (endsWith(filename, ".txt")) ...
> else if (endsWith(filename, ".zvd")) ...
>
> For the loop, see, e.g., the ListFilesRecursively macro
> http://rsb.info.nih.gov/ij/macros/ListFilesRecursively.txt
>
> Michael
> ________________________________________________________________
>
> On 30 May 2008, at 09:07, Christophe Leterrier wrote:
>
>> Hi Zhengyu,
>>
>> Just get all your file names as an array using getFileList() and the
>> loop on all names to detect the last three characters of the names
>> using substring(name, 0, LengthOf(name)-4) (I could I've messed the
>> indexes !). Store that as a new extensions[] array and then put your
>> whole macro in a for+if loop (loop an all extensions, test if
>> extension is .tif).
>>
>> Sorry I don't have a macro at hand that does that to give you the  
>> code
>
>> directly...
>>
>> Christophe
>>
>> On Fri, May 30, 2008 at 6:05 AM, Pang, Zhengyu (GE, Research)
>> <[hidden email]> wrote:
>>> Dear all,
>>>
>>> I have made a macro to batch process images under a folder. But some
>>> files are not images and I need to ignore these files. How do I do
>>> it? I have used a function of getFileList() to read all files, but
>>> how do I ignore some files ending with".zvd" OR ".archive"? Thanks
>>> for your help.
>>>
>>> Zhengyu
>>>
>>>>               g Global Research Center
>>>>
>>>> ___________________________________________________________________
>>>> _
>>>> __
>>>>
>>>>           Zhengyu Pang, Ph.D.
>>>                        Bioanalytics and Protein Science Laboratory
>>>                        Biosciences Global Technology Organization
>>>>               One Research Circle, K1 5B37A
>>>>               Niskayuna, NY12309
>>>>               * [hidden email]
>>>>               *(518) 387-4015
>>>>
>>>>
>>>
Reply | Threaded
Open this post in threaded view
|

Re: Chose only specific file on a folder

ctrueden
In reply to this post by Pang, Zhengyu (GE Global Research)
Hi Zhengyu,

Today's daily build of Bio-Formats (
http://www.loci.wisc.edu/ome/formats.html) contains a macro extension
function that allows you to test a file for whether it is one of the formats
that Bio-Formats handles. Here is an example macro:

run("Bio-Formats Macro Extensions");
name=File.openDialog("Choose a file");
thisType="";
Ext.isThisType(name, thisType);
if (thisType == "true") showMessage("File is supported!");
else showMessage("File is an unknown type...");

This approach eliminates the need to explicitly test a large number of
filename extensions.

-Curtis

On Thu, May 29, 2008 at 11:05 PM, Pang, Zhengyu (GE, Research) <
[hidden email]> wrote:

> Dear all,
>
> I have made a macro to batch process images under a folder. But some
> files are not images and I need to ignore these files. How do I do it? I
> have used a function of getFileList() to read all files, but how do I
> ignore some files ending with".zvd" OR ".archive"? Thanks for your help.
>
> Zhengyu
>
> >               g Global Research Center
> >
> > ______________________________________________________________________
> >
> >           Zhengyu Pang, Ph.D.
>                        Bioanalytics and Protein Science Laboratory
>                        Biosciences Global Technology Organization
> >               One Research Circle, K1 5B37A
> >               Niskayuna, NY12309
> >               * [hidden email]
> >               *(518) 387-4015
> >
> >
>