R – How to create directories specified by a mapper in Ant


Given a fileset

<fileset id="myFiles" dir=".">
    <include name="**/*.file"/>

How do I create a sub-directory at each file in the set, named after the filename without the extension?

For example, given the files folderA/X.file and folderA/folderB/Y.file, I want to create the directories folderA/X and folderA/folderB/Y

Best Solution

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" />
      <fileset dir="the_dir" includes="**/.tmp"/>

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.