使用大小、日期和时间回显 Fileset 中的每个文件 [英] Echo each file in Fileset with size, date and time

查看:22
本文介绍了使用大小、日期和时间回显 Fileset 中的每个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm converting a DOS batch file to Ant. At the end of the batch file, I print out a list of files copied including size, date and time using the DOS dir command. I would like to do the same at the end of the Ant script. So far I have:

<!-- 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>

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

How can I modify the above to print each file on a separate line, with size, date and time?

推荐答案

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

There is a solution based on an external Tasksuite called Ant Flaka. With Ant Flaka you get access to the underlying fileobjects and their properties (name,mtime,size..) from your fileset. no need to open an external process via 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
...

这篇关于使用大小、日期和时间回显 Fileset 中的每个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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