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 5954641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:59:58+00:00 2026-05-22T17:59:58+00:00

I’m trying to copy the newest file from a directory using Ant, ideally I’d

  • 0

I’m trying to copy the newest file from a directory using Ant, ideally I’d like to have a filter on the filename too (eg: ‘*file.java’), but I don’t have any idea of how to do this

I’ve included my script so far, but it’s breaking in the JavaScript and I’ve not got enough experience to know why.

<project name="test1" basedir=".">

    <property file="../local.properties" />
    <property file="../build.properties" />
    <property file="../default.properties" />

    <target name="init">        
        <copy todir=".">
            <fileset dir="/path/to/files">
                <scriptselector language="javascript">
                    var files = basedir.list();
                    var mostRecent = true;
                    for(var i = 0; i < files.size(); i++) {
                        mostRecent = mostRecent && (filename >= files[i]);
                    }
                    self.setSelected(mostRecent);
                </scriptselector>
            </fileset>
        </copy>
    </target>
</project>

edit: just realised the site i got the above JavaScript code from states that this selector is “to select only the newest file of a directory where each file has a time stamp as its filename” so my example won’t work because it’s using the name as the modified date. This leads to the question of how to get the modified date of a file in JavaScript (or any other language which works with Ant)

  • 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-22T17:59:59+00:00Added an answer on May 22, 2026 at 5:59 pm

    Answer was:

    <target name="init">
         <copy todir="." flatten="true">
            <last>
                <sort>
                    <date xmlns="antlib:org.apache.tools.ant.types.resources.comparators"/>
                    <resources>
                        <fileset dir="/path/to/files/">
                            <include name="*sdk*" />
                        </fileset>
                    </resources>
                </sort>
            </last>
        </copy>
    </target>
    

    edit: changed first to last and added filter

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have thousands of HTML files to process using Groovy/Java and I need to
I have a reasonable size flat file database of text documents mostly saved in
I am trying to loop through a bunch of documents I have to put

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.