ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jim Fuller" <>
Subject RE: Telling DirectoryScanner to scan each directory separately.
Date Mon, 26 Jan 2004 08:59:54 GMT

> -----Original Message-----
> From: Antony paul [] 
> Sent: 26 January 2004 05:42
> Subject: Telling DirectoryScanner to scan each directory separately.

>    I am writing a custom task which needs to get the list of 
> included files 
> for each directory but not any subdirectory and files inside 
> it. First I 
> have to get all included directories which is set in the 
> build file. Then I 
> will scan each individual directory to get the included files. While 
> scanning a directory I dont want to get any subdirectory name 
> or files in 
> subdirectory. How to do this.

There was a question last week on this, I will repeat my answer....avoid
using matchingtask.

Here is an example that takes a fileset;

import java.util.Enumeration;
import java.util.Vector;


public class AntFileSetTest extends Task{
	private Vector filesets = new Vector();

    public void addFileset(FileSet fileset) {

    public void execute(){

   log("executing Xindice Ant Task");

int fileCount = 0;
int successCount = 0;

Enumeration enum = filesets.elements();


	FileSet fileset = (FileSet) enum.nextElement();
	DirectoryScanner ds = fileset.getDirectoryScanner(getProject());
	String[] files = ds.getIncludedFiles();

        for(int i=0; i<files.length; i++) {


			File f = new File(fileset.getDir( getProject()

			if (process(f)){


System.out.println("task working properly");

protected boolean process(File file){
        System.out.println("file processed");
        return true;


The process method will do something on the individual file, whereas the
enum snippet does the hard work in the execute method.

>   I am using 1.5.4. Custome task is extending MatchingTask. 
> Also a minor 
> problem. I am using the same build file to compile and run 
> the custom task. 
> First compile, make it a jar, copy the jar file to 
> ANT_HOME\lib directory 
> then call the target to run the task. If I run the task in 
> one step it will 
> run the old class file. I have to launch ant a second time to 
> run the newly 
> copied task. Is it possible to compile and run it in one step ?.

Without seeing your build file, I can only assume that you are not
explicitly defining the classpath. 

Gl, jim fuller

> rgds
> Antony Paul

> _________________________________________________________________
> Let the new MSN Premium Internet Software make the most of 
> your high-speed 
> experience.
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

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

View raw message