Echo each file in Fileset with size, date and time

前端 未结 2 2060
别那么骄傲
别那么骄傲 2020-12-21 06:54

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 comma

相关标签:
2条回答
  • 2020-12-21 07:25

    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>
    

    output =

    ...  
       [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
    ...
    
    0 讨论(0)
  • I don't think that is available in any of the core Ant tasks.

    You could write your own custom task to do this.

    Alternatively, you could use the Apply task to execute a system command like dir for each file in a fileset. For example:

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

    Following your comment below, you could check whether all your zip files were newer than some target file (which you could create before creation of the zips) using the Uptodate task.

    0 讨论(0)
提交回复
热议问题