gpt4 book ai didi

ant - 使用大小、日期和时间回显 Fileset 中的每个文件

转载 作者:行者123 更新时间:2023-12-04 21:30:52 26 4
gpt4 key购买 nike

我正在将 DOS 批处理文件转换为 Ant。在批处理文件的末尾,我使用 DOS dir 命令打印出复制的文件列表,包括大小、日期和时间。我想在 Ant 脚本的末尾做同样的事情。到目前为止,我有:

<!-- LIST COPIED FILES -->
<target name="summary" depends="backup">
<fileset id="zipfiles" dir="${dest}" casesensitive="yes">
<include name="*.zip"/>
</fileset>

<property name="prop.zipfiles" refid="zipfiles"/>
<echo>${prop.zipfiles}</echo>
</target>

我如何修改上面的内容以在单独的行上打印每个文件,包括大小、日期和时间?

最佳答案

有一个基于名为 Ant Flaka 的外部任务套件的解决方案.使用 Ant Flaka,您可以访问文件集中的底层文件对象及其属性(名称、mtime、大小..)。无需通过 apply/cmd 打开外部进程

<project name="demo" xmlns:fl="antlib:it.haefelinger.flaka">
<fl:install-property-handler />

<!-- as fileset has no absolute pathnames we need
path combined with pathconvert -->
<path id="foobar">
<fileset dir="/home/gilreb/Downloads">
<include name="*.zip"/>
</fileset>
</path>

<pathconvert property="zipfiles" refid="foobar"/>

<!-- iterate over the listentries, get access to
the underlying fileobject and echo its properties -->
<fl:for var="f" in="split('${zipfiles}', ':')">
<echo>
#{ format('filename %s, last modified %tD, size %s bytes', f.tofile.toabs,f.tofile.mtime,f.tofile.size) }
</echo>
</fl:for>

</project>

输出=

...  
[echo] filename /some/path/apache-ant-1.8.2-bin.zip, last modified 03/16/11, size 10920710 bytes
[echo]
[echo] filename /some/path/apache-ant-1.8.2-src.zip, last modified 03/16/11, size 8803388 bytes
[echo]
[echo] filename /some/path/apache-ant-antunit-1.1-bin.zip, last modified 04/17/11, size 70477 bytes
...

关于ant - 使用大小、日期和时间回显 Fileset 中的每个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5959763/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com