view content of directory made with ant xml

176 views Asked by At

I have an xml file with ant tasks.

One of the tasks is

<mkdir dir="someDirectory"/>

How can I view the contents of this directory?

I tried

<echo>ls someDirectory</echo>

but this does not work

1

There are 1 answers

0
martin clayton On

How you do it likely depends on what you need to do with the resulting information.

Here's some ideas that might help.

<property name="dir" value="someDirectory" />

<fileset dir="${dir}" id="myls" />
<echo>${toString:myls}</echo>

<exec executable="sh">
  <arg line=" -c 'ls -alF ${dir}'" />
</exec>

The first uses a <fileset> to gather the set of files, then the toString helper to show the list.

The second runs the unix ls command using an <exec> task - which is what you appear to be trying.

For a test directory I get this output:

 [echo] 1:2:3:4

 [exec] total 0
 [exec] drwxr-xr-x  6 mjc  staff  192 10 Apr 11:30 ./
 [exec] drwxr-xr-x  6 mjc  staff  192 10 Apr 11:32 ../
 [exec] -rw-r--r--  1 mjc  staff    0 10 Apr 11:28 1
 [exec] -rw-r--r--  1 mjc  staff    0 10 Apr 11:28 2
 [exec] -rw-r--r--  1 mjc  staff    0 10 Apr 11:28 3
 [exec] -rw-r--r--  1 mjc  staff    0 10 Apr 11:30 4