【问题标题】:Copying files from source directory to destination directory using ant使用ant将文件从源目录复制到目标目录
【发布时间】:2015-07-29 16:18:15
【问题描述】:

我想在以下条件下使用 ANT 将一些特定文件从源目录复制到目标目录。

源文件夹包含以下文件

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

我想复制文件名以36000及以上开头的文件。

输出目录应包含以下文件

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

【问题讨论】:

    标签: ant maven-antrun-plugin


    【解决方案1】:

    一个想法是在文件名上使用正则表达式来限制数字范围。

    示例

    ├── 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>
    

    【讨论】:

    • 谢谢马克..但我不能真正使用正则表达式,因为我的输入 (36000) 被配置为一个属性,它会随着版本动态变化。请建议我继续前进。
    • @Vamsi 在这种情况下,我建议使用基于脚本的选择器。示例见:stackoverflow.com/questions/11531631/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-11
    相关资源
    最近更新 更多