This is really simple, but it's something I couldn't find in the
system...maybe I didn't look closely enough, but there it is...it uses
the <include> and <exclude> tags to selectively delete files from a
directory structure.

Enjoy

John Casey
/*
 * MultiDelete.java
 *
 * Created on September 28, 2000, 8:31 PM
 */


package org.apache.tools.ant.taskdefs;

import org.apache.tools.ant.*;
import java.io.*;
import java.util.*;

/** MultiDelete: This task type will scour the directory tree below the 
basedir, and delete files 
 * matching one of the patterns specified by include sub-tags, and NOT matching 
the ones designated by 
 * the exclude sub-tags.
 *
 * @author  John Casey ([EMAIL PROTECTED])
 * @version 0.1
 */
public class MultiDelete extends MatchingTask {

        /** Executes the task. */
    public void execute() throws BuildException{
        String[] files = 
getDirectoryScanner(project.resolveFile(".")).getIncludedFiles();

        for(int i=0; i<files.length; i++){
            File f = new File(files[i]);
            if(!f.exists()){
                throw new BuildException("ANT found a non-existent file " +
                                        "and tried to delete it...\n" +
                                        "THIS IS A PROBLEM!");
            }
            System.out.println("[multidelete] Deleting file: " + files[i]);
            if(!f.delete()){
                System.out.println("\tCOULD NOT DELETE " + files[i]);
                project.log("Could not delete file: " +
                                        files[i]);
            }
        }
    }
}
begin:vcard 
n:Casey;John
tel;pager:(785)532-5000 ext 313
tel;home:(785)776-4769
tel;work:(785)532-7427
x-mozilla-html:TRUE
url:http://monster.lib.ksu.edu/~jdcasey/resume.html
org:Kansas State University Libraries;Library Network Services
adr;quoted-printable:;;Hale Library=0D=0Amailstop LNS=0D=0AKansas State University=0D=0A;Manhattan;Kansas;66506;United States
adr:;;KSU;Manhattan;Kansas;66506;United States
version:2.1
email;internet:[EMAIL PROTECTED]
title:Network Intern
fn:John Casey
end:vcard

Reply via email to