简体   繁体   English

使用Ant查找具有最新版本号的文件

[英]Use Ant to find file with latest version number

I want to use ant to find the file with the latest version number. 我想使用ant查找具有最新版本号的文件。 For example, I have a file directory named tomcat with the following files: 例如,我有一个名为tomcat的文件目录,其中包含以下文件:

  • apache-tomcat-6.0.37.zip apache-tomcat-6.0.37.zip
  • apache-tomcat-6.0.38.zip apache-tomcat-6.0.38.zip
  • apache-tomcat-6.0.39.zip apache-tomcat-6.0.39.zip

I want ant to determine that apache-tomcat-6.0.39.zip is the latest file. 我希望蚂蚁确定apache-tomcat-6.0.39.zip是最新文件。 Is there a way to do this? 有没有办法做到这一点?

Thanks! 谢谢!

Use resource collections, see last and sort . 使用资源集合,请参阅lastsort fe : fe:

<project>

 <path id="foo">
  <last>
    <sort>
      <fileset dir="C:/some/path" includes="**/apache-tomcat-*.zip"/>
    </sort>
  </last>
 </path>

  <echo>$${foo} => ${toString:foo}</echo>

</project>

output : 输出:

[echo] ${foo} => C:\some\path\apache-tomcat-6.0.39.zip
  • use <pathconvert> to get file names from the relevant <fileset> . 使用<pathconvert>从相关的<fileset>获取文件名。
  • use <sortlist> to sort the filenames in natural String order . 使用<sortlist>natural String order对文件名进行排序。
  • pick the last filename from the list. 从列表中选择最后一个文件名。

try this: 尝试这个:

<fileset dir="${your.base.dir}" id="one">
   <include name="**/apache-tomcat-.*.zip"/>
</fileset>
<pathconvert property="orig.list" refid="one" pathsep=","/>
<sortlist property="sorted.list" value="${orig.list}" delimiter="," />
<propertyregex property="result" input="${sorted.list}" regexp=",?([^,]+?)$" select="\1"/>

inputList: <property name="one" value="ab-2,ab-5,ab-1,ab-3,ab-4"/> inputList: <property name="one" value="ab-2,ab-5,ab-1,ab-3,ab-4"/>
outputList: [echo] ab-5 outputList: [echo] ab-5

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM