3

我正在将 DOS 批处理文件转换为 Ant。在批处理文件的末尾,我使用 DOSdir命令打印出复制的文件列表,包括大小、日期和时间。我想在 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>

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

4

2 回答 2

3

有一个基于名为Ant Flaka的外部任务套件的解决方案。使用 Ant Flaka,您可以从文件集中访问底层文件对象及其属性(名称、时间、大小..)。无需通过 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
...
于 2011-05-13T13:17:10.240 回答
2

我认为这在任何核心 Ant 任务中都不可用。

您可以编写自己的自定义任务来执行此操作。

或者,您可以使用Applydir任务为文件集中的每个文件执行系统命令。例如:

<apply executable="cmd" osfamily="windows">
<arg value="/c"/>
<arg value="dir"/>
<fileset dir=".">
  <include name="*.zip"/>
</fileset>
</apply>

根据您在下面的评论,您可以使用Uptodate任务检查您的所有 zip 文件是否比某些目标文件(您可以在创建 zip 之前创建)更新。

于 2011-05-11T13:37:51.370 回答