Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6561503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:35:45+00:00 2026-05-25T13:35:45+00:00

Hello I wasn’t quite sure how to title this question, but I’ll explain why

  • 0

Hello I wasn’t quite sure how to title this question, but I’ll explain why I’m trying to do.

First of all, I have a folder that contains SQL scripts in a specific format, which is updateXtoY.sql, where X and Y are integers. What I need is to know which Y is the highest number. (basically, to know which is the latest script)

So if I have in my folder “scripts/” 3 files:

update3to5.sql
update2to5.sql
update1to6.sql

the result I need is to have assign a property ‘latest.version’ the value of 6.

From that point I can easily run the script. So the problem I have is 3-fold:

1- How to load the file names into a data structure.

2- How to iterate over the data structure.

3- How to evaluate each file name so that I can extract the “Y” part of the file and get the highest value. (I’m reading on regex right now)

I’m new to ANT and I’m not sure if this is possible and/or feasible.

Thanks for any suggestions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:35:45+00:00Added an answer on May 25, 2026 at 1:35 pm

    The first part of the task – getting the filenames into a ‘structure’ is best done using a FileSet – say for SQL scripts in a directory called scripts:

    <fileset dir="scripts" includes="*.sql" id="versions" />
    

    That creates an Ant resource collection that can be referred to using the id versions.
    The collection knows about your SQL script files.

    Using (as you suggest) a regexp mapper, we can convert the set of files into a collection of strings, holding just the version parts from the filenames:

    <mappedresources id="versions">
        <fileset dir="scripts" includes="*.sql" />
        <regexpmapper from="update.*to(.*).sql" to="\1" />
    </mappedresources>
    

    In this example versions now holds a ‘list’, which would be "5,5,6" for your example files.

    It gets trickier now, because you probably need to carry out a numeric sort on what is a list of strings – to avoid 10 sorting as ‘less’ than 9. Ant ships with an embbeded Javascript interpreter, so you could use that to find the maximum. Another option would be to make use of the numeric sorting capability that ant-contrib has to offer.

    Here’s a Javascript ‘max finder’:

    <scriptdef name="numeric_max" language="javascript">
        <attribute name="property" />
        <attribute name="resources_id" />
        <![CDATA[
        var iter = project.getReference(
           attributes.get( "resources_id" )
       ).iterator( );
    
        var max_n = 0.0;
        while ( iter.hasNext() )
        {
            var n = parseFloat( iter.next() );
            if ( n > max_n ) max_n = n;
        }
        project.setProperty( attributes.get( "property" ), max_n );
        ]]>
    </scriptdef>
    

    That defines a new Ant XML entity – numeric_max – that looks like a task, and can be used to find the numeric maximum of a collection of strings.
    It’s not perfect – there’s no validation of the strings, and I’ve used floats rather than ints.

    Combining that with the mappedresources above:

    <mappedresources id="versions">
        <fileset dir="scripts" includes="*.sql" />
        <regexpmapper from="update.*to(.*).sql" to="\1" />
    </mappedresources>
    <numeric_max property="latest.version" resources_id="versions" />
    
    <echo message="Latest SQL script version: ${latest.version}." />
    

    When I run that with your three files I get:

    [echo] Latest SQL script version: 6.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry for the poor question wording I wasn't sure how to describe this. I
Ok guys, this is my first thread, and I have searched online but with
Hello I have the following error by git-fsck, which cannot be cleaned by git-gc
Hello again ladies and gents! OK, following on from my other question on ASP.NET
Hello I was writing a Regular Expression (first time in my life I might
Hello can anybody solve this please I'm creating the object in the action class
Hello I am compiling a program with make but I get the error of
Hello all you helpful folks @ stackoverflow! Best resources for Java GUI's? Looking at
Hello I am working with a simulator that uses rcS scripts to boot, this
Hello we have an SQL server application running over a low bandwith connection. We

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.