ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Diane Holt <>
Subject Re: task to delete nonmatching files?
Date Sat, 20 Apr 2002 01:45:08 GMT
--- Jon Schewe <> wrote:
> My build script currently has a task in it that copies files from one
> directory to another changing the extension, using a file mapper. This
> works great. Now the problem I have is that if I delete a file in the
> source directory I'd like to have ant delete the file in the destination
> directory the next time it builds, but only for files that are missing
> [...]
> Has someone already done this, or do I need to write my own task?

Didn't write you a task, since it's faster for me to do it in Javascript
(anything to avoid doin' the dishes :)

 <property name="src.dir" location="src"/>
 <property name="dest.dir" location="dest"/>
 <target name="sync">
   <fileset dir="${dest.dir}" id="chkfiles">
     <include name="**/*.ship"/>
   <pathconvert pathsep="," property="chkfiles" refid="chkfiles">
     <map from="${dest.dir}" to=""/>
   <script language="javascript"> <![CDATA[
     var srcdir = projname.getProperty("src.dir");
     var destdir = projname.getProperty("dest.dir");
     var files = projname.getProperty("chkfiles");
     var filesep = projname.getProperty("file.separator");
     var st = new StringTokenizer(files, " ,");
     while (st.hasMoreTokens()) {
       var filename = st.nextToken();
       var pos = filename.indexOf('.');
       chkfilename = filename.substring(0, pos);
       chkfilename = srcdir.concat(chkfilename).concat(".orig");
       var chkfile = new File(chkfilename);
       if(!chkfile.exists()) {
         filename = destdir.concat(filename);
         showit = projname.createTask("echo");
         showit.setMessage( "Deleting leftover file: " + filename );

$ ant sync
     [echo] Deleting leftover file: C:\TEMP\dest\dir1\c\foo.ship
     [echo] Deleting leftover file: C:\TEMP\dest\dir2\b\baz.ship

(Change the extensions to what yours really are, and change the "showit"s
to deletes.)



Do You Yahoo!?
Yahoo! Games - play chess, backgammon, pool and more

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message