2014-12-27 187 views
-1

有沒有辦法在構建過程中檢查文件的年齡?文件的螞蟻年齡

我想檢查指定的文件是否大於1周。

喜歡的東西

<olderthan property="property.name" file="checked.file" days="7"/> 

我想用touchuptodatetouch只能使用指定的日期或now的。

+0

可能重複1年和超過3個文件](http://stackoverflow.com/questions/11531631/linux-removing-folders-older-than-1-year-and-more-than-3-files) – 2014-12-27 20:49:13

回答

1

馬克的鏈接並沒有解決我的問題,但給我的主意,用腳本

<!-- Check if specified file is newer than age in seconds --> 
<scriptdef name="isNewerThan" uri="composer.ant.mleko" language="javascript"> 
    <attribute name="file"/> <!-- The file to check. --> 
    <attribute name="age"/> <!-- The threshold of file age in seconds. --> 
    <attribute name="property"/> <!-- The name of property to set. --> 
    <attribute name="value"/> <!-- The value to set the property to. Defaults to "true". --> 
    <attribute name="else"/> <!-- The value to set the property to if the condition evaluates to false. By default the property will remain unset. --> 
    <![CDATA[ 
     var fileName = attributes.get("file"); 
     var age = attributes.get("age"); 
     var property = attributes.get("property"); 
     var value = attributes.get("value"); 
     var elseValue = attributes.get("else"); 

     var maxAge = parseInt(age, 10); 

     if(null === fileName)self.fail("`file` is required"); 
     if(null === age || isNaN(maxAge))self.fail("`age` is required and must be valid int string"); 
     if(null === property)self.fail("`property` is required"); 
     if(null === value)value="true"; 

     var file = new java.io.File(fileName); 
     var ageInSeconds = (Date.now() - file.lastModified())/1000; 

     if(ageInSeconds < maxAge){ 
      project.setProperty(property, value); 
     }else if(null !== elseValue){ 
      project.setProperty(property, elseValue); 
     } 
    ]]> 
</scriptdef> 
0

要與<tstamp>使用<touch><uptodate>在一起:

<tstamp> 
    <format property="one.week.ago" offset="-7" unit="day" pattern="MM/dd/yyyy hh:mm aa"/> 
</tstamp> 

<touch file="source-file.txt" datetime="${one.week.ago}"/> 

<uptodate 
    property="target-file-modified-in-previous-week" 
    targetfile="target-file.txt" 
> 
    <srcfiles dir= "." includes="source-file.txt"/> 
</uptodate> 

<condition property="is-target-file-out-of-date" value="true" else="false"> 
    <isset property="target-file-modified-in-previous-week"/> 
</condition> 

<echo>is-target-file-out-of-date: ${is-target-file-out-of-date}</echo> 
的[Linux的刪除文件夾比老