ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gilbert Rebhan <...@schillbaer.de>
Subject Re: getting filename from dir listing
Date Fri, 21 Sep 2007 18:18:51 GMT

Hi,

Mario Madunic wrote:
> I would like to get the filename of the first file in a directory and then get a
> particular part of the filename.
> 
> There has to be a much easier and cleaner way of doing this.

You want the first part of the filename, right ?

with a dir like that =
J:\test>dir /B
20070921_0001.xml
20070921_0002.xml
20070921_0003.xml

you can go with <script>, and put the
string in a property for further
ant processing, i.e. =

<script language="ruby">
<![CDATA[
str=File.basename(Dir["J:/test/*.xml"].sort[0]).gsub(/(\w{8}).+/, $1)
$project.setProperty "myproperty", str
]]>
</script>
...
<echo>
$${myproperty} == ${myproperty}
</echo>

will give you =
${myproperty} == 20070921

Regards, Gilbert




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message