如何使用文件集中的apache ant创建多个新的符号链接?

时间:2011-04-07 20:27:24

标签: unix ant symlink

ant中的符号链接任务创建单个,记录现有,重新创建现有或删除单个符号链接。我想创建指向不同目录中给定目录中所有文件的符号链接。

1 个答案:

答案 0 :(得分:3)

实现它的最简单方法(在编码方面)是在antcontrib的For task

的帮助下
<for param="file">
  <path>
    <fileset dir="${src.dir}" includes="*"/>
  </path>
  <sequential>

    <basename property="@{file}.basename" file="@{file}">
    <symlink link="${dest.dir}/${@{file}.basename}" resource="@{file}"/>
  </sequential>
</for>

如果您不想依赖ant-contrib,可以尝试以下方法(注意:我根本没有测试它):

  1. 手动创建几个链接 $ {dest.dir}。
  2. 运行 在$ {dest.dir}。
  3. 现在您有了一个模板属性文件,您将使用构建说明重新创建该文件:

    <pathconvert pathsep="${line.separator}" property="file.list">
      <fileset dir="${src.dir}" includes="*"/>
    </pathconvert>
    <echo message="${file.list}" file="${file-list.file}" append="false"/>
    

    现在使用regexp过滤器按下文件

    <copy file="${file-list.file}" tofile="${dest-dir}/.link.properties">
      <filterchain>
        <tokenfilter>
          <!-- I leave regex as an exercise to the reader -->
          <replaceregex pattern="..." replace="..." flags="..."/>
        </tokenfilter>
      </filterchain>
    </copy>
    

    最后做symlink-recreate。

    <symlink action="recreate">
      <fileset dir="${dest.dir}" includes=".link.properties"/>  
    </symlink>
    
相关问题