ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tom Dimock <t...@cornell.edu>
Subject Re: deletefiles
Date Mon, 12 Jun 2000 17:51:35 GMT
Michael - Your code looks much like mine...

public class Deletefiles extends MatchingTask {

    private File delDir;

    public void setDeldir(String src) {
        delDir = project.resolveFile(src);
    }

    public void execute() throws BuildException {
        if (delDir == null) {
            throw new BuildException("deldir attribute must be set!");
        }

        if (!delDir.exists()) {
            throw new BuildException("deldir does not exist!");
        }

        DirectoryScanner ds = super.getDirectoryScanner(delDir);

        String[] files = ds.getIncludedFiles();
        if (files.length > 0) {
            project.log("Deleting " + files.length + " files");
            for (int i=0; i<files.length; i++) {
                File f = new File(delDir, files[i]);
                if (f.exists()) {
                  if (f.isDirectory()) { 
                    project.log("Directory: " + f.getAbsolutePath() + 
                    " cannot be removed with deletefiles.  Use Deltree
instead.");
                  } else {
                    project.log("Deleting: " + f.getAbsolutePath());
                    f.delete();
                  }
               }
            }
        }
    }

----------------------------------------------------------------------------
       Tom Dimock  ----  Cornell University  ----  tad1@cornell.edu
"There go my people.  I must follow them, for I am their leader."  M. Gandhi

Mime
View raw message