Thanks Mike. 

Sent from my iPhone

> On Oct 30, 2020, at 5:10 AM, Mike Thomsen <mikerthom...@gmail.com> wrote:
> 
> You need to use the listFiles() that has a FilenameFilter interface in it:
> 
> https://docs.oracle.com/javase/8/docs/api/java/io/File.html#listFiles-java.io.FilenameFilter-
> 
>> On Thu, Oct 29, 2020 at 5:12 PM KhajaAsmath Mohammed
>> <mdkhajaasm...@gmail.com> wrote:
>> 
>> Hi,
>> 
>> I have a requirement where I need to get the file count from the path using 
>> the groovy script.
>> 
>> I came up with the below but unable to filter and count only txt files . Any 
>> suggestions please?
>> 
>> import org.apache.commons.io.IOUtils
>> import java.nio.charset.*;
>> import java.io.*;
>> 
>> def flowFile = session.get()
>> if(!flowFile) return
>> 
>> 
>> def eahpath = flowFile.getAttribute("eahpath")
>> def count = new File(eahpath).listFiles().size();    // I need to filter 
>> only txt files and get count
>> flowFile=session.putAttribute(flowFile,"eahfilecount",count+"");
>> def fail = false
>> if(fail){
>> session.transfer(flowFile, REL_FAILURE)
>> fail = false
>> } else {
>> session.transfer(flowFile, REL_SUCCESS)
>> }
>> 
>> Thanks,
>> Asmath

Reply via email to