Search code examples
datephing

Prune old files in a directory with phing


This target works fine

<target name="cleanlogs">
   <echo msg="clean log do nothing !!!!not ready!!!!" />
  <fileset dir="/var/www/myapp/log" id="deleteLogs">
   <include name="**/debug*.log" />
  </fileset>
  <delete>
   <fileset refid="deleteLogs" />
  </delete>
 </target>

I want add something like

<date datetime="xxxxxx" when="before"/> 

or

<date seconds="xxxxxx" when="before"/> 

to delete only logs older than 5 days

How to build xxxxx in phing ??

<tstamp> 

dont return "timestamp" :-/


Solution

  • Here is a proposition of solution

        <?xml version="1.0" encoding="UTF-8"?>
        <project name="Project" default="format"   basedir=".">
            <target name="format">
                    <tstamp>
                            <format property="DATE" pattern="%s" />
                    </tstamp>
                    <php expression="${DATE}-(3600*24*5)" returnProperty="NEWDATE"/>
                    <php expression="time()-(3600*24*5)" returnProperty="EVALUATEDTIME"/>
    
                    <echo>DATE = ${DATE}</echo>
                    <echo>NEWDATE = ${NEWDATE}</echo>
                    <echo>EVALUATEDTIME = ${EVALUATEDTIME}</echo>
    
            </target>
        </project>
    

    Actually you can put anything in the eval and directly compute whatever you need.