ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Diane Holt <hol...@yahoo.com>
Subject Re: task to delete nonmatching files?
Date Sat, 20 Apr 2002 01:45:08 GMT
--- Jon Schewe <jpschewe@mtu.net> 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"/>
   </fileset>
   <pathconvert pathsep="," property="chkfiles" refid="chkfiles">
     <map from="${dest.dir}" to=""/>
   </pathconvert>
   <script language="javascript"> <![CDATA[
     importClass(java.io.File);
     importClass(java.util.StringTokenizer);
     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 );
         showit.execute();
       }
     }
     ]]>
   </script>
 </target>

$ ant sync
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.)

Diane


=====
(holtdl@yahoo.com)



__________________________________________________
Do You Yahoo!?
Yahoo! Games - play chess, backgammon, pool and more
http://games.yahoo.com/

--
To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>


Mime
View raw message