如何使用 Ant 删除除最新的 2 个文件之外的所有文件 [英] How to delete all but latest 2 files using Ant

查看:39
本文介绍了如何使用 Ant 删除除最新的 2 个文件之外的所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Ant,我必须从备份文件夹中删除除最新的 2 个文件之外的所有文件.

Using Ant, I have to delete all but the latest 2 files from a backup folder.

我试图否定 last count="2",但找不到正确的资源顺序.

I tried to negate last count="2", but could not found the right Resources order.

目前我正在这样做:

<delete verbose="true">
    <difference>
        <resources>
            <fileset dir="${backup}"/>
        </resources>
        <last count="2">
            <sort>
                <date/>
                <resources>
                    <fileset dir="${backup}"/>
                </resources>
            </sort>
        </last>
    </difference>
</delete>

有没有更简单的方法?

推荐答案

这个问题导致了一个 Ant 增强请求 已应用于 Ant 1.9.5(在撰写本文时尚未发布).直到 1.9.4 没有更好的纯 Ant 解决方案,除非您想自己实现资源集合.

This question has lead to an Ant enhancement request that has been applied for Ant 1.9.5 (which hasn't been released, yet, at the time of this writing). Up to 1.9.4 there is no better pure-Ant solution unless you want to implement a resource collection yourself.

从 Ant 1.9.5 开始你可以使用

Starting with Ant 1.9.5 you can use

<delete verbose="true">
    <allbutlast count="2">
        <sort>
            <date/>
            <resources>
                <fileset dir="${backup}"/>
            </resources>
        </sort>
    </allbutlast>
</delete>

这篇关于如何使用 Ant 删除除最新的 2 个文件之外的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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