You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Mark (JIRA)" <ji...@apache.org> on 2019/02/07 15:37:00 UTC
[jira] [Created] (IO-599) RFE: FileUtils.glob[One]([File
rootSearchDir, ] String antFileExpr)
Mark created IO-599:
-----------------------
Summary: 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
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}
"**" match anything including file separators, "*" match 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
(v7.6.3#76005)