Question: I want do compile all `*.less` scripts in a specific folder and it subdirs with **less-rhino-1.1.3.js**. 

There is an example on github for doing this for a specific file, which works perfect. But I want to do the same for a complete folder. I tried a lot, here is my last try.

It doesn't work, `propertyregex` seems not to be standard ANT, I don't want to use such things. I am not even sure if this code would work.

```
<project name="test" default="main" basedir="../../">
<property name="css.dir" location="public/css"/>
<property name="tool.less" location="bin/less/less-rhino-1.1.3.js"/>
<property name="tool.rhino" location="bin/tools/rhino/js.jar"/>
<macrodef name="lessjs">
    <attribute name="input" />
    <attribute name="output" />
    <sequential>
        <java jar="${tool.rhino}" fork="true" output="@{output}">
            <arg path="${tool.less}"/>
            <arg path="@{input}"/>
        </java>
        <echo>Lessjs: generated @{output}</echo>
    </sequential>
</macrodef>

<target name="main">
     <echo>compiling less css</echo>
     <fileset dir="${css.dir}" id="myfile">
          <filename name="**/*.less" />
     </fileset>
     <property name="lessfilename" refid="myfile"/>
     <propertyregex property="cssfilename"
          input="${lessfile}"
          regexp="^(.*)\.less$"
          replace="^\1\.css$" 
          casesensitive="true" />
     <lessjs input="lessfile" output="cssfilename"/>
</target>
</project>

```

Answer: 
I was able to piece together a working solution with the help of a couple of SO answers:

[ANT script to compile all (css) LESS files in a dir and subdirs with RHINO](https://stackoverflow.com/questions/6909106/ant-script-to-compile-all-css-less-files-in-a-dir-and-subdirs-with-rhino)

[How to correctly execute lessc-rhino-1.6.3.js from command line](https://stackoverflow.com/questions/21961790/how-to-correctly-execute-lessc-rhino-1-6-3-js-from-command-line)

I had to download LESS 1.7.5 from GitHub and modify the Ant target to look like this. The `-f` argument and LESS JavaScript was key: 

```
<property name="css.dir" value="WebContent/css"/>
<property name="less.dir" value="less"/>
<property name="tool.rhino.jar" value="test-lib/rhino-1.7R4.jar"/>
<property name="tool.rhino.lessc" value="test-lib/lessc-rhino-1.7.5.js"/>
<property name="tool.rhino.less" value="test-lib/less-rhino-1.7.5.js"/>
<target name="compile-less" description="compile css using LESS">
    <apply dir="${css.dir}" executable="java" parallel="false" failonerror="true">
        <fileset dir="${less.dir}">
            <include name="styles.less"/>
        </fileset>
        <arg value="-jar"/>
        <arg path="${tool.rhino.jar}"/>
        <arg value="-f"/>
        <arg path="${tool.rhino.less}"/>
        <arg path="${tool.rhino.lessc}"/>
        <srcfile/>
        <mapper type="glob" from="*.less" to="${css.dir}/*.css"/>
        <targetfile/>
    </apply>
</target>

```
If maven is an option for you, you could try [wro4j-maven-plugin](http://code.google.com/p/wro4j/wiki/MavenPlugin) or [wro4j-runner](http://code.google.com/p/wro4j/wiki/wro4jRunner) (which is a command line utility).

Using one of these, all you have do is to create an resource model descriptor (wro.xml):

```
<groups xmlns="http://www.isdc.ro/wro">
  <group name="g1">
    <css>/path/to/*.less</css>
  </group>
</groups>

```

The rest will be handled by the wro4j library. No need to carry about how rhino works or other details.

Disclaimer: I'm working on wro4j project