php - Copy a single file to all sub directories under a certain directory using Ant Script -


how can make script using ant copy single file index.html sub-directories of directory.

i'm trying build ant script copy index.html on sub-directories. if file exists in specific sub-directory, file should replaced.

my initial structure:

directory    sub-directory aa        file1        file2        ...    sub-directory ab        file1        file2        index.html        ...       sub-directory aba           file1           file2           ...     .... 

i want achieve this:

directory    sub-directory aa        file1        file2        index.html  <- file copied        ...    sub-directory ab        file1        file2        index.html  <- file replaced        ...       sub-directory aba           file1           file2           index.html  <- file copied           ...     .... 

thanks in advance. regards.

the following example uses groovy ant task.

example

├── build.xml ├── lib │   └── groovy-all-2.1.6.jar ├── src │   └── index.html └── target     └── directorya         ├── index.html         ├── subdirectoryaa         │   └── index.html         └── subdirectoryab             ├── index.html             └── subdirectoryaba                 └── index.html 

build.xml

<project name="demo" default="copy">     <path id="build.path">       <pathelement location="lib/groovy-all-2.1.6.jar"/>    </path>     <target name="copy">       <taskdef name="groovy" classname="org.codehaus.groovy.ant.groovy" classpathref="build.path"/>        <dirset id="trgdirs" dir="target/directorya"/>        <groovy>          project.references.trgdirs.each {             ant.copy(file:"src/index.html", todir:it, overwrite:true, verbose:true)          }       </groovy>    </target>  </project> 

notes:

  • the groovy script able loop thru directories contained in ant dirset.
  • groovy has access normal ant tasks. note "overwrite" flag on copy operation.

Comments