Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
804 views
in Technique[技术] by (71.8m points)

ant - Echo each file in Fileset with size, date and time

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.6k users

...