Java Mailing List Archive

http://www.ant-tasks.com/

Apache Ant Archive

» Ant Users List
» Ant Developers List
Only deleting an empty directory (-tree)

Only deleting an empty directory (-tree)

2005-05-30       - By Antoine Levy-Lambert
Reply:     1     2     3     4     5  

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 <DAMKE@(protected)>
> An: "Ant Users List" <user@(protected)>
> 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: user-unsubscribe@(protected)
For additional commands, e-mail: user-help@(protected)


©2008 ant-tasks.com - Jax Systems, LLC, U.S.A.