首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >文件蚂蚁年龄

文件蚂蚁年龄
EN

Stack Overflow用户
提问于 2014-12-27 18:44:36
回答 2查看 205关注 0票数 0

在构建过程中是否有一种检查文件时间的方法?

我想检查指定的文件是否早于1周。

有点像

代码语言:javascript
复制
<olderthan property="property.name" file="checked.file" days="7"/>

我想使用触摸uptodate,但是touch只能使用指定的日期或now

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-12-28 13:30:27

Mark的链接没有解决我的问题,但给了我使用脚本的想法

代码语言:javascript
复制
<!-- 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>
票数 2
EN

Stack Overflow用户

发布于 2014-12-29 16:57:38

<touch><uptodate><tstamp>一起使用

代码语言:javascript
复制
<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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27670373

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档