-->

Copying files from source directory to destination

2019-09-01 04:02发布

问题:

I want to copy some specific files from source directory to destination directory on below condition using ANT.

Source folder contains the following files

  • 35001_abc.sql
  • 38001_abc.sql
  • 38002_abc.sql
  • 39001_abc.sql

I want to copy the files with filenames starting with 36000 and above.

The Output directory should contain the following files

  • 38001_abc.sql
  • 38002_abc.sql
  • 39001_abc.sql

回答1:

One idea is to use a regular expression on the filename to restrict ranges of digits.

Example

├── build.xml
├── src
│   ├── 35001_abc.sql
│   ├── 38001_abc.sql
│   ├── 38002_abc.sql
│   ├── 39001_abc.sql
│   ├── 41001_abc.sql
│   └── 46001_abc.sql
└── target
    ├── 38001_abc.sql
    ├── 38002_abc.sql
    ├── 39001_abc.sql
    ├── 41001_abc.sql
    └── 46001_abc.sql

build.xml

<project name="demo" default="copy">

  <property name="src.dir"   location="src"/>
  <property name="build.dir" location="target"/>

  <target name="copy">
    <copy todir="${build.dir}" overwrite="true" verbose="true">
      <fileset dir="${src.dir}">
        <filename regex="^(3[6-9]|[4-9]\d)\d{3}_abc.sql$"/>
      </fileset>
    </copy>
  </target>

  <target name="clean">
    <delete dir="${build.dir}"/>
  </target>

</project>