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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:29:46+00:00 2026-05-29T17:29:46+00:00

I have a directory tree that I need to process as follows: I have

  • 0

I have a directory tree that I need to process as follows:

  • I have a certain file that needs to be copied to a select few sub directories
  • A sub directory of interest is one that contains a file within which I can regex match a known search string

Ideally I would like to:

  • Perform a regex match across all files within a directory
  • If the regex matches, copy the file to that directory

The trouble is that I am quite new to ANT and I’m having difficulties finding my way around. I can’t find any tasks in the docs about per directory operations based on regex search. The closest thing I’ve found is a regex replace task (<replaceregexp>) that can search and replace patterns across files.

Is this even possible? I’d really appreciate a sample to get started with. I apologize for requesting code – I simply don’t know how to begin composing the tasks together to achieve this.

Alternatively I have the option of hardcoding all the copy operations per directory, but it would mean manually keeping everything in sync as my project grows. Ideally I’d like to automate it based on the regex search/copy approach I described.

Thanks!

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

    Your requirement is a bit non-standard, so I’ve solved it using a custom Groovy task.

    Here’s a working example:

    <project name="find-files" default="copy-files">
    
        <!--
        ======================
        Groovy task dependency
        ======================
        -->
        <path id="build.path">
            <pathelement location="jars/groovy-all-1.8.6.jar"/>
        </path>
        <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>
    
    
        <!--
        =========================
        Search for matching files
        =========================
        -->
        <target name="search-files">
            <fileset id="filesContainingSearchString" dir="src">
                <include name="**/*.txt"/>
                <containsregexp expression="[4-6]\.[0-9]"/>
            </fileset>
        </target>
    
        <!--
        ===================================
        Copy file into each directory found
        ===================================
        -->
        <target name="copy-files" depends="search-files">
            <groovy>
            project.references.filesContainingSearchString.each { file ->
                def dir = new File(file.toString()).parent
    
                ant.copy(file:"fileToBeCopied.txt", toDir:dir)
            }
            </groovy>
        </target>
    
    </project>
    

    Notes:

    • Groovy jar can be downloaded from Maven Central
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have been sent a directory tree of source code that i want to
I have a python script that is trying to create a directory tree dynamically
So I have a directory tree as follows: pluginlist.py plugins/ __init__.py plugin1.py plugin2.py ...
I have written an Air program that mirrors a directory tree. The problem is
I have a large filesystem that I need to traverse for errors. Each file
I have a program that creates an object for each file in a directory
I have a tree that displays the directory and another panel that displays the
i want to have a xml file in the user specifed directory. for that
I'm new to visual studio, coming from Delphi. I have a directory tree full
I have used copydir to copy a directory tree but it is deprecated. My

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.