Reputation: 1
I want to copy today's date log files from server using an Ant script. I have tried with following script but it is copying all the files from folder. But I would like to copy files like modified date is today's date.
<project name="MyProject" default="copy" basedir=".">
<property file="${basedir}/build.properties"/>
<tstamp>
<format property="time.stamp" pattern="MM-dd-yyyy"/>
</tstamp>
<target name="copy" description="copy files">
<echo>copying files</echo>
<copy todir="D:\software\Files\${time.stamp}" >
<fileset dir="C:\GatorNet\EAServer\logs" >
<include name="**/*.log"/>
</fileset>
</copy>
</target>
</project>
Upvotes: 0
Views: 1383
Reputation: 1
<tstamp>
<format property="TODAY_MY" pattern="yyyyMMddHHmmss" locale="en,UK" />
</tstamp>
<echo message="todaysDate: ${TODAY_MY}"/>
<echo message="Copy war files to Dir...."/>
<copy todir="/todir/">
<fileset dir="/fromdir/"/>
<globmapper from="*.war" to="*.war.${TODAY_MY}"/>
</copy>
Upvotes: 0
Reputation: 16255
You could use a date selector in your fileset.
Copying the example from that manual page:
<fileset dir="${jar.path}" includes="**/*.jar"> <date datetime="01/01/2001 12:00 AM" when="before"/> </fileset>
Selects all JAR files which were last modified before midnight January 1, 2001.
For your case, I think you want something like this:
<tstamp/>
<echo>${DSTAMP}</echo>
<mkdir dir="${DSTAMP}"/>
<copy todir="${DSTAMP}" includeemptydirs="no">
<fileset dir=".">
<date datetime="${DSTAMP}" pattern="yyyyMMdd" when="after"/>
<include name="*"/>
</fileset>
</copy>
Upvotes: 1