You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gary D. Gregory (Jira)" <ji...@apache.org> on 2022/06/23 13:06:00 UTC

[jira] [Commented] (IO-599) RFE: FileUtils.glob[One]([File rootSearchDir, ] String antFileExpr)

    [ https://issues.apache.org/jira/browse/IO-599?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17558068#comment-17558068 ] 

Gary D. Gregory commented on IO-599:
------------------------------------

This is already in the JRE, see {{java.nio.file.Files.newDirectoryStream(Path, String)}}

> RFE: FileUtils.glob[One]([File rootSearchDir, ] String antFileExpr)
> -------------------------------------------------------------------
>
>                 Key: IO-599
>                 URL: https://issues.apache.org/jira/browse/IO-599
>             Project: Commons IO
>          Issue Type: Improvement
>            Reporter: Mark
>            Priority: Minor
>
> Can we please introduce a simpler file search method than the existing ones that are using filters?
> Currently I'm using the ant lib's DirectoryScanner for that purpose. However, ant comes with quite a few dependencies, introducing unnecessary overhead and bloat.
> Examples:
> {code:java}
> // select all sub directories (final slash) of cwd
> File[] f = FileUtils.glob("**/");
> // select first sub dir, null if there is none
> File f = FileUtils.globFirst("**/");
> // exception if there is none
> File f = FileUtils.globFirstE("**/");
> // select exactly one sub dir, return null if there are more or less
> File f = FileUtils.globOne("**/");
> // select exactly one sub dir, throw exception if there are more or less
> File f = FileUtils.globOneE("**/");
> // two parameter version allows to start recursive search in specified dir
> File f = FileUtils.globOneE(new File("."), "**/");
> {code}
> "\*\*" matches anything including file separators, "\*" matches anything excluding file separators, a final "/" indicates directory matching, a missing final slash indicates file matching. The function always traverses the entire directory hierarchy, starting at cwd by default (not counting optimizations). The search pattern is standardized, ie. "/" on all platforms, ie. "/" is not the platform file separator.
> Here is an example implementation:
> https://github.com/jjYBdx4IL/misc/blob/df9c239c56640f0d3e27d1b5d510b62f5726253f/io-utils/src/test/java/com/github/jjYBdx4IL/utils/io/FindUtilsTest.java#L105
> https://github.com/jjYBdx4IL/misc/blob/df9c239c56640f0d3e27d1b5d510b62f5726253f/io-utils/src/main/java/com/github/jjYBdx4IL/utils/io/FindUtils.java



--
This message was sent by Atlassian Jira
(v8.20.7#820007)