ANT 构建 - 删除多个目录
我在构建文件中添加了一个目标,以使用时间戳删除超过 4 天的备份:
<tstamp>
<format pattern="MM/DD/yyyy HH:MM aa" offset="-4" property="backup.deletedate" />
</tstamp>
<echo message="Deleting log directories created on or before ${backup.deletedate}" />
<delete verbose="true">
<dirset dir="${backup.dir}/CI">
<date datetime="${backup.deletedate}" when="before" checkdirs="true" />
</dirset>
<dirset dir="${backup.dir}/DEV_MASTER">
<date datetime="${backup.deletedate}" when="before" checkdirs="true" />
</dirset>
</delete>
但是它仅从第一个目录 (CI) 中删除并跳过第二个目录。
如何将其设置为从两个目录中删除?
I have added a target in a build file to delete backups that are older than 4 days by using a timestamp:
<tstamp>
<format pattern="MM/DD/yyyy HH:MM aa" offset="-4" property="backup.deletedate" />
</tstamp>
<echo message="Deleting log directories created on or before ${backup.deletedate}" />
<delete verbose="true">
<dirset dir="${backup.dir}/CI">
<date datetime="${backup.deletedate}" when="before" checkdirs="true" />
</dirset>
<dirset dir="${backup.dir}/DEV_MASTER">
<date datetime="${backup.deletedate}" when="before" checkdirs="true" />
</dirset>
</delete>
However it ony deletes from the first directory (CI) and skips the second.
How can I set it to remove from BOTH directories?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
似乎 dirset 集合正在跳过非空目录。我通过对整个备份目录使用文件集来克服它:
工作就像一个魅力!
Seems the dirset collection was skipping non-empty directories. I overcame it by using a fileset for the entire backup dir:
Works like a charm!
合并你的目录。
Merge your dirsets.
这是使用
exec
任务删除第一级子目录的解决方案(对于清理夜间构建系统很有用):如果您不需要限制第一级子目录,则可以使用以下命令:
如果您还需要包含文件,请使用以下命令:
它适用于 Windows 和 Linux 系统。与纯 Ant 删除相比,其优点之一是 ant 不会生成任何文件集,因此速度可能更快。
Here is a solution using the
exec
task for deleting first level sub-directories (useful for cleaning a nightly build system):If you don't need to limit to first level subdirectories, you can use the following:
If you need to include files too, use the following:
It works on Windows and Linux systems. One advantage over the pure Ant deletion is that ant does not generate any fileset and so is possibly faster.