Within an ant file, I am trying to convert windows style path separators to unix style. I have the following:
<path id="basedir.path">
<!-- ${basedir} is a project attribute. -->
<pathelement path="${basedir}" />
</path>
<pathconvert property="adjusted_basedir" refid="basedir.path">
<mapper>
<globmapper from="*" to="*" handledirsep="yes"/>
</mapper>
</pathconvert>
<echo level="verbose" message="Basedir: ${basedir}" />
<echo level="verbose" message="Adj Basedir: ${adjusted_basedir}" />
but the output of adjusted_basedir is the same as basedir. I have tried using
<mapper type="regexp" from="\\" to="/" />
but then the output of adjusted_basedir is simply "/". How do I convert path separators from windows to unix style? I want to avoid using add-ons to ant for this (so ant-contrib is out).
Try using a filtermapper:
<pathconvert property="adjusted_basedir" refid="basedir.path">
<filtermapper>
<replacestring from="\" to="/" />
</filtermapper>
</pathconvert>
See https://ant.apache.org/manual/Types/mapper.html.
There is also an attribute to do this in the pathconvert task:
<pathconvert property="adjusted_basedir" refid="basedir.path" dirsep="/" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With