sungyong
sungyong

Reputation: 2499

Get filtered file list from apache FileUtils

I'm tring to get file list with specific name.
But it is not easy to use FileterUtils from apache commons.

My goal is getting all files with pattern *_fact_.*.

I tried to as below.

Iterator<File> picFiles = 
  FileUtils
  .iterateFiles(
     uploadFile.getParentFile(),  
     FileFilterUtils.nameFileFilter("*_fact_1.*"), 
     null
   );

But no results.

It might cause my wrong usage of FileFilterUtils.
What doing I wrong?

Upvotes: 2

Views: 258

Answers (1)

Jim Garrison
Jim Garrison

Reputation: 86774

You need to be using WildcardFileFilter instead of NameFileFilter.

Iterator<File> picFiles = 
  FileUtils
  .iterateFiles(
     uploadFile.getParentFile(),  
     new WildcardFileFilter("*_fact_1.*"), 
     null
   );

Upvotes: 1

Related Questions