Example 2

Delete all .svn directories in d1's directory hierarchy.

JavaScript

// Note1: The SuperParentOrFilter matches an entity if any of its parent // entities matches the filter. // // Note2: Create the SuperParentOrFilter to include the tested entity in the // tests. Otherwise the .svn directory itself would not be deleted. new TreeDeleteTF(). addSource( new DirectoryAndFilter(d1, new SuperParentOrFilter( DirectoryFilter.FILTER.and( new EntityNameFilter(".svn")), true))).run();

Example 3

This is an alternative way of deleting the .svn directories compared to the previous example. Instead of using the SuperParentOrFilter with the TreeDeleteTF, it uses the RecursiveActionTF to define a new TreeDeleteTF task for each .svn directory found.

JavaScript

// Note: It may seem a little dangerous to start a recursive deleter while // we're iterating over the directory hierarchy with another iterator. It should // work fine, though, since we instruct RecursiveActionTF to use a depth-first // iterator. new RecursiveActionTF(). setDepthFirstIterator(true). addSource( new DirectoryAndFilter(d1, DirectoryFilter.FILTER.and( new EntityNameFilter(".svn")))). setTaskFactory( new TreeDeleteTF(). setDeleteRoot(true)).run();

Example 4

This is yet another way of deleting the .svn directories (see the two previous examples). This time, a FilteringIterator is used.

Groovy

import org.entityfs.util.itr.FilteringIterator import org.entityfs.util.* import org.entityfs.util.filter.entity.* import TreeDeleteTF // Note1: Just like in the previous example, it is important that we use // a depth-first iterator. // // Note2, a gotcha: It is not possible to call the Entities.delete method from a // JavaScript, since "delete" is a reserved word there. Use the method // Entities.deleteEntity instead (it does exactly the same thing). def itr = new FilteringIterator( Directories.getDepthFirstIterator(d1), // Groovy lets us combine the filters using & DirectoryFilter.FILTER & new EntityNameFilter(".svn")) while(itr.hasNext()) { dv = itr.next() new TreeDeleteTF(). addSource(dv).run() Entities.deleteEntity dv }

JavaScript

// Note1: Just like in the previous example, it is important that we use // a depth-first iterator. // // Note2, a gotcha: It is not possible to call the Entities.delete method from a // JavaScript, since "delete" is a reserved word there. Use the method // Entities.deleteEntity instead (it does exactly the same thing). var itr = new FilteringIterator( Directories.getDepthFirstIterator(d1), DirectoryFilter.FILTER.and( new EntityNameFilter(".svn"))); while(itr.hasNext()) { dv = itr.next(); new TreeDeleteTF(). addSource(dv).run(); Entities.deleteEntity(dv); }

JRuby

# Note1: Just like in the previous example, it is important that we use # a depth-first iterator. itr = Schmant::FilteringIterator.new( Schmant::Directories.getDepthFirstIterator($d1), Schmant::DirectoryFilter::FILTER.and( Schmant::EntityNameFilter.new(".svn"))) while itr.hasNext dv = itr.next Schmant::TreeDeleteTF.new.addSource(dv).run Schmant::Entities.delete dv end

Jython

# Note1: Just like in the previous example, it is important that we use # a depth-first iterator. itr = FilteringIterator( Directories.getDepthFirstIterator(d1), \ DirectoryFilter.FILTER.and( EntityNameFilter(".svn"))) while (itr.hasNext()): dv = itr.next() TreeDeleteTF(). \ addSource(dv).run() Entities.delete(dv)


* An EntityFS-aware task is implemented using EntityFS. This means that it uses the filter settings of DirectoryView:s and also that it often can work with other file system implementations than File-based, such as the RAM file system.