You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Jon Schewe <jp...@mtu.net> on 2002/04/20 02:29:02 UTC

task to delete nonmatching files?

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 because it'd get
really expensive to delete all the files and do a full rebuild.  Has someone
already done this, or do I need to write my own task?
-- 
Jon Schewe | http://mtu.net/~jpschewe
For I am convinced that neither death nor life, neither angels 
nor demons, neither the present nor the future, nor any 
powers, neither height nor depth, nor anything else in all 
creation, will be able to separate us from the love of God that 
is in Christ Jesus our Lord. - Romans 8:38-39

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: task to delete nonmatching files?

Posted by Jon Schewe <jp...@mtu.net>.
Diane Holt wrote:

> --- Jon Schewe <jp...@mtu.net> wrote:
> 
>>What about if the files are in different trees?
>>
> 
> I'm not sure what you mean. The way it currently works is that they're in
> different subdirs under the base directory, just because that's the way I
> assumed you'd be doing it -- there's nothing special about that fact. If
> that's not case, then you'd just set your source and destination directory
> properties to point to where they do exist (ie., in my example ${src.dir}
> and ${dest.dir}). I assume the subdir hierarchy of the copied files is
> kept, since you didn't mention flattening it.


I see, it should work for general trees.  Upon first look it seemed that 
it'd only work if the files were in the same directory, which I also 
need.  Thanks.

-- 
Jon Schewe | http://mtu.net/~jpschewe | jpschewe@mtu.net
For I am convinced that neither death nor life, neither angels
nor demons, neither the present nor the future, nor any
powers, neither height nor depth, nor anything else in all
creation, will be able to separate us from the love of God that
is in Christ Jesus our Lord. - Romans 8:38-39


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: task to delete nonmatching files?

Posted by Diane Holt <ho...@yahoo.com>.
--- Jon Schewe <jp...@mtu.net> wrote:
> What about if the files are in different trees?

I'm not sure what you mean. The way it currently works is that they're in
different subdirs under the base directory, just because that's the way I
assumed you'd be doing it -- there's nothing special about that fact. If
that's not case, then you'd just set your source and destination directory
properties to point to where they do exist (ie., in my example ${src.dir}
and ${dest.dir}). I assume the subdir hierarchy of the copied files is
kept, since you didn't mention flattening it.

Diane

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



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

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: task to delete nonmatching files?

Posted by Jon Schewe <jp...@mtu.net>.
Diane Holt wrote:

> --- Jon Schewe <jp...@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 :)
> 

Thanks.  What about if the files are in different trees?

-- 
Jon Schewe | http://mtu.net/~jpschewe | jpschewe@mtu.net
For I am convinced that neither death nor life, neither angels
nor demons, neither the present nor the future, nor any
powers, neither height nor depth, nor anything else in all
creation, will be able to separate us from the love of God that
is in Christ Jesus our Lord. - Romans 8:38-39


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: task to delete nonmatching files?

Posted by Diane Holt <ho...@yahoo.com>.
--- Diane Holt <ho...@yahoo.com> wrote:
>      var filesep = projname.getProperty("file.separator");

Oops, unused var -- you can get rid of it.

Diane

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



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

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: task to delete nonmatching files?

Posted by Diane Holt <ho...@yahoo.com>.
--- Jon Schewe <jp...@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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>