commons-io : FileFilters

3 messages Options
Embed this post
Permalink
Dave Westerman-2

commons-io : FileFilters

Reply Threaded More More options
Print post
Permalink
I'm trying to use Apache Commons IO FileFilters, and it's obvious I don't
clearly understand them, because I can't get them to work trying to find a
subdirectory.

Here's my code:

File configCellDir = new File( FilenameUtils.concat( wasProfile ,
"config/cells" ) ) ;
IOFileFilter dmgrFilter = FileFilterUtils.nameFileFilter( "dmgr" ) ;
Collection dmgrDirs = FileUtils.listFiles( configCellDir , dmgrFilter ,
TrueFileFilter.INSTANCE ) ;


I'm trying to find a subdirectory 'dmgr' anywhere in the
<WAS_PROFILE>/config/cells filesystem. The directory is definitely there,
but the dmgrDirs collection is empty. I've also tried:
WildcardFileFilter dmgrFilter = new WildcardFileFilter( "*dmgr*" ) ;
and:
RegexFileFilter dmgrFilter = new RegexFileFilter( ".*dmgr.*" ) ;
All without success.

However, if I try to find a file, it works.

IOFileFilter serverIndexFilter = FileFilterUtils.nameFileFilter(
"serverindex.xml" ) ;
Collection serverIndexFiles = FileUtils.listFiles( configCellDir ,
serverIndexFilter , TrueFileFilter.INSTANCE ) ;

Can anyone tell me what I'm doing wrong?

Thanks!
DLW
Jukka Zitting

Re: commons-io : FileFilters

Reply Threaded More More options
Print post
Permalink
Hi,

On Thu, Oct 29, 2009 at 3:15 PM, Dave Westerman <[hidden email]> wrote:
> I'm trying to use Apache Commons IO FileFilters, and it's obvious I don't
> clearly understand them, because I can't get them to work trying to find a
> subdirectory.
> [...]
> Can anyone tell me what I'm doing wrong?

The findFiles() method will only return files, not directories.

BR,

Jukka Zitting

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Dave Westerman-2

Re: commons-io : FileFilters

Reply Threaded More More options
Print post
Permalink
DUH! I totally missed that, thanks for pointing that out.

So, with the following:

File configCellsDir = new File( FilenameUtils.concat( wasProfile ,
"config/cells" ) ) ;
String[] cellNames = configCellsDir.list( DirectoryFileFilter.INSTANCE ) ;

I can get all the subdirectories directly under the 'cells' directory.

But I take it there is no way to find subdirectories recursively? The
'dmgr' subdir is several levels deep, and trying this doesn't work:

WildcardFileFilter dmgrFilter = new WildcardFileFilter( "*dmgr*" ) ;
String[] dmgrDirs = configCellsDir.list( dmgrFilter ) ;

Is there any way to do this, without having to write my own
DirectoryWalker implementation?

Thanks again!
DLW


Jukka Zitting <[hidden email]> wrote on 10/29/2009 10:39:27 AM:

> [image removed]
>
> Re: commons-io : FileFilters
>
> Jukka Zitting
>
> to:
>
> Commons Users List
>
> 10/29/2009 10:40 AM
>
> Please respond to "Commons Users List"
>
> Hi,
>
> On Thu, Oct 29, 2009 at 3:15 PM, Dave Westerman <[hidden email]>
wrote:
> > I'm trying to use Apache Commons IO FileFilters, and it's obvious I
don't
> > clearly understand them, because I can't get them to work trying to
find a

> > subdirectory.
> > [...]
> > Can anyone tell me what I'm doing wrong?
>
> The findFiles() method will only return files, not directories.
>
> BR,
>
> Jukka Zitting
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>