Ant Dirset of all Sub-Directories which contain Files

1.2k views Asked by At

I need to make a dirset containing all low-level directories which contain files. So for example a structure like:

.
├── _a
├── _b
|   ├── file1.class
|   └── file2.class
├── _c
|   └── _d
|        └── file3.class
├── _e
|   ├── _f
|   └── _g
└── _h
    └── file4.class

Would result in a dirset of the directories:

./b/
./c/d/
./h/

How could I achieve this?

2

There are 2 answers

0
Redmatters On BEST ANSWER

I found the solution, it was to first create a fileset in the directory that I needed to scan, then use a pathconvert in order to get the parent directories of all files and to get the relative path.

All that was left was to create a dirset with an includes that specifies the paths from the pathconvert (it also removes duplicate directory entries).

<pathconvert pathsep="," property="filePaths">
    <map from="${basedir}/" to="" />
    <!-- get parent of file -->
    <regexpmapper from="(.*)\${file.separator}" to="\1" />
    <path>
        <!-- change dir to your directory -->
        <fileset dir="${basedir}/dir" casesensitive="yes">
            <include name="**/*.*" />
        </fileset>
    </path>
</pathconvert>

<dirset dir="${basedir}/" casesensitive="yes" includes="${filePaths}" />
0
Rao On

Not sure in which task you wanted.

Anyways, try fileset as given below:

<fileset dir="${base.dir}" casesensitive="yes">
  <include name="**/*.*"/>
</fileset>