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

  • Home
  • SEARCH
  • 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 6195351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:27:13+00:00 2026-05-24T03:27:13+00:00

I have an ant task that uses an apply task to run a script

  • 0

I have an ant task that uses an apply task to run a script on a group of files.

I have a directory structure resultant of something like this:
mkdir -p a/{b,c,d,e}/f

Normally (if I pass no arguments), I would like ant to run on all fs.
That is, if I called ant mytask, it should process: a/b/f, a/c/f, a/d/f, a/e/f. This already works using apply and patternsets.

However, when I pass it an optional argument called foo, it should only call the script on a/foo/f.

So if I called ant mytask -foo b, it should process a/b/f only, and not the others.

I have read this SO post, which explains ways of passing arguments, and I have looked at the ant documentation regarding properties, and conditionals. But I am still unable to piece them together in a way that works.

Also, I do not want to use one of the suggestions from the SO above which called for arguments like this:

<arg value="${arg0}"/>
<arg value="${arg1}"/>

I want to be able to call it as ant mytask -foo valueoffoo for any arbitrary foo.

Thanks.


I tried martin clayton’s suggestion below and have code like:

<target name="mytask">
  <property name="foo" value="*" />
  <apply executable="perl">
    <arg value="somescript"/>
    <dirset id="them" dir="a">
      <include name="${foo}/*/f" />
    </dirset>
  </apply>
</target>

The above does what I want.

Note 1: In my actual code I use a patternset instead of dirset but it should work the same.

Note 2: In my original question I said the directory structure was a/{b,c,d,e}/f. It is in fact a bit more complicated, hence the * in the include above. I omitted that the first time around because it did not seem relevant.

  • 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-24T03:27:15+00:00Added an answer on May 24, 2026 at 3:27 am

    You can do this – albeit with a slightly different command-line syntax –
    using a property ‘override’.

    First, in the buildfile, construct your fileset or dirset from a property foo,
    something like this:

    <property name="foo" value="*" />
    <dirset id="them" dir="a">
        <include name="${foo}/f" />
    </dirset>
    

    This will give you your default behaviour – processing all
    subdirectories of a that themselves have a subdirectory f.

    Now, if you run Ant like this:

    ant -Dfoo=d
    

    Only directory a/d/f will be processed.

    This works because Ant properties are not mutable – well, not normally anyway –
    so the command-line definition of foo prevents the one within the buildfile from being used.

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

Sidebar

Related Questions

I have an Ant script that performs a copy operation using the 'copy' task
I have an application that uses several configuration files (let just consider appli.properties here).
I have an ant task that contains javac task inside. It reports about error
Let's say I have a file-system that looks a little something like this: C:\stuff\build.xml
I want to use the FTP task in ant, and I have found the
I have the problem that an specific step in Ant can only be executed
I have a project that uses a third party library in the form of
I have a project that uses generics and a few Java 1.5/6 bits and
I have used the jarbundler ant task to create an OSX (10.6.4) XXX.app for
I have created a custom Ant task as per one of my previous posts

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.