How to create directories specified by a mapper in Ant

一个人想着一个人 提交于 2019-12-02 01:36:17

The ant touch task supports creating files, parent dirs and filename mapping, so can be used to achieve this:

  <target name="mkdirs">
    <touch mkdirs="true">
      <fileset dir="the_dir"/>
      <mapper type="glob" from="*.file" to="the_dir/*/.tmp" />
    </touch>
    <delete>
      <fileset dir="the_dir" includes="**/.tmp"/>
    </delete>
  </target>

This creates temporary files in target dirs (creating the dirs if the don't exist) then deletes the temporary files leaving the dirs you wanted.

You would be using for task to iterate on your file list. But I have not come across any substring type of utility in Ant which you can use to strip the extension and create the directory. Do search for this utility, if its not there then you need to implement an Ant task to do that.

Sorry to answer my own question. Unless someone knows otherwise, there appears to be no way for out-of-the-box ANT to create directories (e.g. using mkdir) relative to entries in a fileset.

Ant-Contrib contains useful for loop tasks, as Bhushan suggests, which could possibly perform this sort of task.

Had some better things to be getting on with, so in the end, I just wrote a batch file called by an ANT task (apply tasks can iterate over filesets).

<apply executable="cmd" failonerror="1">
    <arg value="/c"/>
    <arg line="build\tools\makeRelDir.bat"/>
    <fileset dir=".">
        <include name="**/*.file"/>
    </fileset>
</apply>

where the batch file does this: mkdir %~dp1%~n1

(Why is it so hard to do something some simple in ANT? Am I missing something?)

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