Search code examples
antlast-modified

Change 'modified' time for all files in directory to the 'modified' time of files in other directory using ANT


Higuys.

I have a small problem with ant touch task. What I need to do:

I have directory with sources:

C:\development\source\project\staticfiles\cartridge\rules\*.drl

and all files from it are copied to 'target' dir:

C:\development\target\project\release\rules\*.drl.

As they are copied using ant, the 'modified' time for newly created files in the 'target' dir is changed respectively, but I need to change to 'modified' time of a corresponding file from the 'source' dir after they are copied. Or in other words, I need 'modified' time of both files to be the same.

I guess ant touch can help here, but I do not know how to handle two directories at a time.

Thank you for your help.


Solution

  • you may use the preservelastmodified attribute of the <copy> task.

    preservelastmodified : Give the copied files the same last modified time as the original source files.

    eg.

    <copy todir="${dest.dir}" preservelastmodified="true">
        <fileset dir="${src_dir}"/>
    </copy>