ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Antoine Levy-Lambert <>
Subject Re: DirectoryScanner exclude subdirectories ?
Date Thu, 06 Oct 2005 20:10:39 GMT
Gilbert Rebhan wrote:

>Matt Benson wrote:
>>I can't remember the entire context of this
>>discussion... but includes/excludes are used by
>>DirectoryScanner.  To include only child "files" of
>>basedir, the correct include pattern is "*".  However,
>>this includes directories which are basedir's
>>immediate children.  To further restrict the selection
>>to non-directory files, use the <type> selector as
>my first post was =
>i want to use the DirectoryScanner in an own task.
>i want to exclude subdirectories and only including
>the files in the root of basedir.
>DirectoryScanner ds = fs.getDirectoryScanner(getProject());
>        String[] includes = {"*.*"};
>        String[] excludes = {"**\\**"};
>        ds.setIncludes(includes);
>        ds.setExcludes(excludes);
>String[] names = ds.getIncludedFiles();
>What are the correct include / exclude patterns to
>include ownly the files in root of basedir but exclude
>all subdirectories and files in subdirectories ?
>i want to use it in a selfwritten task not in an
Hello Gilbert,

>Question =
>is it possible to use DirecoryScanner standalone or only combined
>with a type selector ?
>i believe it's easier to roll my own solution instead of using
>DirectoryScanner combined with a selector.
It is always a matter of taste. I like to use the Ant Apis, which are
well documented, maintained, and stay mostly compatible from version to
<fileset dir="foo/bar">
   <depth max="1"/>
    <type type="file"/>
is what you are looking for. You just need to find out from the code of
AbstractFileSet how to do this programmatically (probably 4 lines of code).
Something like

// assuming variable myProject : current ant project
// myFs : the fileset you are defining
AndSelector mySelector = new AndSelector();
DepthSelector depthsel = new DepthSelector();
TypeSelector ts = new TypeSelector();

>Regards, Gilbert


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message