Copying files from source directory to destination directory using ant

淺唱寂寞╮ 提交于 2019-12-13 21:56:12

问题


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>


来源:https://stackoverflow.com/questions/31705943/copying-files-from-source-directory-to-destination-directory-using-ant

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!