I am attempting to rename a file and haven't found a simple way to do so. My initial thought was to use the <move> task. However, this only appears to work the first time. For example, given the following target:
<target name="move.test">
<copy file="move.tst" tofile="move.src"/>
<touch file="move.src" verbose="true"/>
<move file="move.src" tofile="move.tgt"/>
</target>
The first time I execute it I see the following successful log:
move.test:
[copy] Copying 1 file to C:\_Commons\Support\Test\move.src.
[touch] Touching file C:\_Commons\Support\Test\move.src with 08/13/2004 15:37:54.
[move] 1 files moved.
However, the second time I execute it (without cleaning anything up) I get the following failure log:
move.test:
[copy] Copying 1 file to C:\_Commons\Support\Test\move.src.
[touch] Touching file C:\_Commons\Support\Test\move.src with 08/13/2004 15:38:04.
BUILD FAILED
C:\_Commons\Support\Test\test.build(26,4):
Failed to move C:\_Commons\Support\Test\move.src to C:\_Commons\Support\Test\move.tgt.
Cannot create a file when that file already exists.
Even if I set overwrite="true" on the <move> task I get the same error. I don't actually think this is situation this attribute was meant to address, but I tried it anyway.
So the question is, shouldn't the <move> task overwrite a file when the source is newer than the target as the following quote from the help implies, "Files are only moved if the source file is newer than the destination file" ?
So far, the only thing I can get to work is either a <delete><move> combination or a <copy><delete> combination. Both of these force me to set failonerror="false" to handle situations such as a first build or previously failed build which I'd prefer not to do.
Any suggestions would be greatly appreciated.
Thanks,
Tom