If I understand your requirements right, you want to delete recursively all 
directories which contain a marker file.

So maybe you could use this (have a deeper look at the <delete> task).


Jan



<project xmlns:au="antlib:org.apache.ant.antunit" xmlns:if="ant:if" 
default="antunit">

    <property name="test.dir" value="test" />

    <!-- from Ant's src/tests/antunit/antunit-base.xml -->
    <target name="antunit">
        <antunit xmlns="antlib:org.apache.ant.antunit">
            <plainlistener />
            <file file="${ant.file}" xmlns="antlib:org.apache.tools.ant" />
        </antunit>
    </target>
    
    <macrodef name="create">
        <attribute name="dir" />
        <attribute name="delete" default="false"/>
        <sequential>
            <mkdir dir="@{dir}" />
            <touch file="@{dir}/file.txt" />
            <touch file="@{dir}/-to-delete-" if:true="@{delete}"/>
        </sequential>
    </macrodef>

    <target name="setUp">
        <create dir="${test.dir}/dir1/dir11/dir111" />
        <create dir="${test.dir}/dir1/dir11/dir112" delete="true"/>
        <create dir="${test.dir}/dir1/dir12/dir121" />
        <create dir="${test.dir}/dir1/dir12/dir122" />
        <create dir="${test.dir}/dir2" delete="true"/>
        <create dir="${test.dir}/dir2/dir21/dir211" />
        <create dir="${test.dir}/dir2/dir21/dir212" />
        <create dir="${test.dir}/dir2/dir22/dir221" />
    </target>
    
    <target name="tearDown">
        <delete dir="${test.dir}" />
    </target>
    
    <target name="testDeleteByMarkerFile">
        <!-- check prepared environment -->
        <au:assertFileExists file="${test.dir}/dir1/dir11/dir111/file.txt"/>
        <au:assertFileExists file="${test.dir}/dir1/dir11/dir112/file.txt"/>
        <au:assertFileExists file="${test.dir}/dir2/file.txt"/>
        
        <!-- delete -->
        <delete includeemptydirs="true">
            <fileset dir="${test.dir}">
                <scriptselector language="javascript">
                    markerfile = new java.io.File(file.getParent(), 
"-to-delete-");
                    self.setSelected(markerfile.exists());
                </scriptselector>
            </fileset>
        </delete>
        
        <!-- check assertions -->
        <au:assertFileExists file="${test.dir}/dir1/dir11/dir111/file.txt"/>
        <au:assertFileDoesntExist 
file="${test.dir}/dir1/dir11/dir112/file.txt"/>
        <au:assertFileDoesntExist file="${test.dir}/dir2/file.txt"/>
    </target>

</project>



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

Reply via email to