Hello Juergen,

I would develop a custom selector (read the important section concepts and
types of ant) which selects empty directories.

read this :
http://ant.apache.org/manual/CoreTypes/custom-programming.html#customselectors
http://ant.apache.org/manual/CoreTypes/selectors.html#customselect
http://ant.apache.org/manual/CoreTypes/selectors-program.html

it might even be possible to define your custom selector in the build file
using a scripting langage and the <scriptdef/> task.
Possible solution :

from 
example of use of java script in a build file :
http://marc.theaimsgroup.com/?l=ant-dev&m=107693336832222&w=2


project name="test">
<script language="beanshell">
      import org.apache.tools.ant.types.selectors.FileSelector;
      import org.apache.tools.ant.BuildException;
      import java.io.File;
      public class EmptyDirSelector extends DataType implements FileSelector
{
                boolean isSelected(File basedir, String filename, File file)
            throws BuildException {
                 if (!file.isDirectory()) {
                    return false;
                    }
                String[] aaa = file.list();
                if (aaa != null) {
                        if (aaa.length == 0) {
                            return true;
                        }
                }
                return false;
            }
      }
      project.addDataTypeDefinition("emptydirselector",
EmptyDirSelector.class);
    </script>
    <mkdir dir="d:/test1/test2/test3/test4"/>
    <mkdir dir="d:/test1/test2/test3/test5"/>
    <echo file="d:/test1/test2/test3/test5/test5.txt">
bonjour
    </echo>
    <delete>
    <dirset dir="d:/test1">
        <emptydirselector/>
    </dirset>
    </delete>
</project>

but :
deleteemptydir.xml:2: org.apache.bsf.BSFException: BeanShell script error:
Sourced file: inline eva
luation of: ``       import
org.apache.tools.ant.types.selectors.FileSelector;       import or . . . ''
: Clas
s: DataType not found in namespace : at Line: 5 : in file: inline evaluation
of: ``       import org.apache.to
ols.ant.types.selectors.FileSelector;       import or . . . '' : DataType
 BSF info: ANT at line: 0 column: columnNo

Total time: 0 seconds


Peter, any idea ?

Antoine

> --- Ursprüngliche Nachricht ---
> Von: Juergen Damke <[EMAIL PROTECTED]>
> An: "Ant Users List" <user@ant.apache.org>
> Betreff: Only deleting an empty directory (-tree)
> Datum: Mon, 30 May 2005 09:16:29 +0200
> 
> I'm searching for a task which traverses a directorytree and removes 
> all empty directories, but leaves those which have any contents.
> 
> Should work unter *NIX and Windows, so a java Task is preferred.
> 
> Mit freundlichen Grüßen / With best regards
> Jürgen Damke
> Portal Automated Function Verification Tests
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to