You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "Rebhan, Gilbert" <Gi...@huk-coburg.de> on 2005/09/30 11:30:46 UTC

DirectoryScanner exclude subdirectories ?

Hi,

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 ?

Regards, Gilbert

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: DirectoryScanner exclude subdirectories ?

Posted by Antoine Levy-Lambert <an...@gmx.de>.
Gilbert Rebhan wrote:

>Hi,
>
>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
>>well.
>>
>>-Matt
>>    
>>
>
>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
>ant(xml)script
>
>  
>
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
version.
<fileset dir="foo/bar">
<and>
   <depth max="1"/>
    <type type="file"/>
</and>
</fileset>
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();
mySelector.setProject(myProject);
DepthSelector depthsel = new DepthSelector();
depthsel.setProject(myProject);
deptsel.setMax(1);
mySelector.appendSelector(depthsel);
TypeSelector ts = new TypeSelector();
ts.setType("file");
ts.setProject(myProject);
mySelector.appendSelector(ts);
myFs.addAnd(mySelector);

>Regards, Gilbert
>
>
>  
>

Cheers,
Antoine

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: DirectoryScanner exclude subdirectories ?

Posted by Matt Benson <gu...@yahoo.com>.
There is no need to exclude anything that wouldn't be
included based on includes.  So if you instantiate a
DirectoryScanner and set its includes to {"*"} it will
find every file and directory that lives immediately
below the specified basedir.  If you intend to use
DirectoryScanner from code, there is really no need to
use the selector, as you retrieve files and
directories with separate API calls against
DirectoryScanner; if you don't want directories, just
don't retrieve them.

-Matt

--- Gilbert Rebhan <an...@schillbaer.de> wrote:

> Hi,
> 
> 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
> > well.
> > 
> > -Matt
> 
> 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
> ant(xml)script
> 
> 
> 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.
> 
> Regards, Gilbert
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@ant.apache.org
> For additional commands, e-mail:
> user-help@ant.apache.org
> 
> 



	
		
______________________________________________________ 
Yahoo! for Good 
Donate to the Hurricane Katrina relief effort. 
http://store.yahoo.com/redcross-donate3/ 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: DirectoryScanner exclude subdirectories ?

Posted by Gilbert Rebhan <an...@schillbaer.de>.
Hi,

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
> well.
> 
> -Matt

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
ant(xml)script


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.

Regards, Gilbert


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: DirectoryScanner exclude subdirectories ?

Posted by Matt Benson <gu...@yahoo.com>.
--- Gilbert Rebhan <an...@schillbaer.de> wrote:
[SNIP]
> if i understand you right =
> if i want to list files in rootdirectory
> only, but exclude all dirs/files beyond rootdir,
> using DirectoryScanner
> ain't possible ?!
> 
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
well.

-Matt



		
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: DirectoryScanner exclude subdirectories ?

Posted by Gilbert Rebhan <an...@schillbaer.de>.
Hi,

Dominique Devienne wrote:
>>       String[] excludes = {"**\\**"};
> 
> 
> Never use back-slashes. It's not portable.
> 
> To include only files and not dirs, you can use a <type> selector. The
> only problem is that it probably twarts the smarts added by Antoine in
> directory scanner to not scan the directories themselves. You end up
> with the correct list of files, simply not as fast. --DD
>

if i understand you right =
if i want to list files in rootdirectory
only, but exclude all dirs/files beyond rootdir, using DirectoryScanner
ain't possible ?!

So i have to roll my own thing.

i thought, i'll take a thing that's already around in core classes of
ant, DirectoryScanner in that case.
OK, i understand that includes/excludes are mostly for naming
conventions, f.e. i want only txtfiles that start with foobar* or
similar.
But it looks like i can't exclude subdirectories, like i that it
were possible with the right pattern.

Regards, Gilbert


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: DirectoryScanner exclude subdirectories ?

Posted by Dominique Devienne <dd...@gmail.com>.
>        String[] excludes = {"**\\**"};

Never use back-slashes. It's not portable.

To include only files and not dirs, you can use a <type> selector. The
only problem is that it probably twarts the smarts added by Antoine in
directory scanner to not scan the directories themselves. You end up
with the correct list of files, simply not as fast. --DD

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org