最新的文件复制与蚂蚁文件名过滤器 [英] Copy newest file with filename filter in Ant

查看:196
本文介绍了最新的文件复制与蚂蚁文件名过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想最新的文件使用Ant的一个目录复制,最好我想对文件名的过滤器太(如:'* file.java'),但我没有任何想法如何做到这一点。

I'm trying to copy the newest file from a directory using Ant, ideally I'd like to have a filter on the filename too (eg: '*file.java'), but I don't have any idea of how to do this

我包括我的剧本,到目前为止,但它打破了JavaScript和我已经没有足够的经验,知道这是为什么。

I've included my script so far, but it's breaking in the JavaScript and I've not got enough experience to know why.

<project name="test1" basedir=".">

    <property file="../local.properties" />
    <property file="../build.properties" />
    <property file="../default.properties" />

    <target name="init">        
        <copy todir=".">
            <fileset dir="/path/to/files">
                <scriptselector language="javascript">
                    var files = basedir.list();
                    var mostRecent = true;
                    for(var i = 0; i < files.size(); i++) {
                        mostRecent = mostRecent && (filename >= files[i]);
                    }
                    self.setSelected(mostRecent);
                </scriptselector>
            </fileset>
        </copy>
    </target>
</project>

编辑:刚刚意识到我得到了网站上来自各国的JavaScript code,这种选择是只选择每个文件都有一个时间戳作为其文件名的目录中的最新文件,所以我的例子荣获 ŧ工作,因为它使用的名称作为修改日期。这导致了如何获得在JavaScript文件的修改日期(或用Ant的其他任何语言)的问题。

edit: just realised the site i got the above JavaScript code from states that this selector is "to select only the newest file of a directory where each file has a time stamp as its filename" so my example won't work because it's using the name as the modified date. This leads to the question of how to get the modified date of a file in JavaScript (or any other language which works with Ant)

推荐答案

答案是:

<target name="init">
     <copy todir="." flatten="true">
        <last>
            <sort>
                <date xmlns="antlib:org.apache.tools.ant.types.resources.comparators"/>
                <resources>
                    <fileset dir="/path/to/files/">
                        <include name="*sdk*" />
                    </fileset>
                </resources>
            </sort>
        </last>
    </copy>
</target>

编辑:改变第一个到最后,并添加过滤器

edit: changed first to last and added filter

这篇关于最新的文件复制与蚂蚁文件名过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆