tags:

views:

60

answers:

3

Is there any command in ant to copy files from one folder structure to another without checking the last modified date/time overwriting files. Basically I want all extra files from folder A to folder B. That is: no files of folder B are replaced but extra files of folder A comes to folder B.

I saw "ant copy" and "ant move" commands, but didn't help. Any suggestions.

A: 

If there isn't an elegant solution you can always do it in a sequence:

  1. <move> folder <B> to <C>
  2. <copy> files of folder <A> to <B>
  3. <copy> files of folder <C> to <B> using overwrite=true

(Do things the other way around, replacing the new files, not the old ones)

seanizer
This didnt help because last modified date time still remains same even if the files are backed up in folder C.
So during Step 3, it doesnt replace the files because folder B (Copied from folder A) files were modified after the one in folder C, so the problem remains same.
no, not if you use overwrite=true in step 3.
seanizer
My bad, that works !
yes, but hendrix's (intentional typo :-)) is more elegant
seanizer
+2  A: 

Just use the <copy> tag with a fileset as **/* and set the overwrite attribute to false explicitly. I use this all the time:

<copy todir="/your/target" overwrite="false">
  <fileset dir="/your/source">
    <include name="**/*" />
  </fileset>
</copy>
Joeri Hendrickx
inculde `**/*` is redundant. That's what `<fileset>` does by default.
Alexander Pogrebnyak
It's the overwrite="false" flag that ensures files are not copied twice
Mark O'Connor
A: 

The simple solution to your problem is to use the overwrite parameter to the copy command. This will ensure that files are not replaced

    <copy todir="B" verbose="true" overwrite="false">
        <fileset dir="A"/>
    </copy>

The more complicated example is to use a fileset selector

    <copy todir="B" verbose="true">
        <fileset dir="A">
            <present targetdir="B" present="srconly"/>
            <date datetime="01/01/2001 12:00 AM" when="after"/>
        </fileset>
    </copy>

In this example I've used a present selector to choose a file isn't present in the target directory (functionally the same as an overwrite check) and I've added an extra date condition to test if the file has been modfied since a certain date.

The selector list is quite extensive.

Mark O'Connor