I am writing a directory path to a text file from ant, which is later read by a Java Application to find another file.
In my ant script I have:
<property name="fulltrainer.dir" location="${trainer.dir}" />
<echo file="${trainer.dir}/properties/commonConfig.properties"># KEY VALUE
CurrentBuildFile=${fulltrainer.dir}\current_build</echo>
in the build.properties file trainer.dir is set to:
trainer.dir=../trainer
It ends up writing:
# KEY VALUE
CurrentBuildFile=C:\Workspaces\ralph\trainer\current_build
to the commonConfig.properties file.
I need it to write:
# KEY VALUE
CurrentBuildFile=C:\\Workspaces\\ralph\\trainer\\current_build
or, I need it to write:
# KEY VALUE
CurrentBuildFile=C:/Workspaces/ralph/trainer/current_build
How can I do that?
Double Backslashes (\\)Two backslashes are used as a prefix to a server name (hostname). For example, \\a5\c\expenses is the path to the EXPENSES folder on the C: drive on server A5. See UNC, \\, path and forward slash.
Windows traditionally uses the backslash ( \ ) to separate directories in file paths. (For example, C:\Program Files\PuppetLabs .)
It is expected that a directory not end in a slash. Any expectation that a directory ends in a slash is wrong.
You can use forward slashes ( / ) instead of backward slashes ( \ ) on Windows (as is the case with Linux® and UNIX). If you use backward-slashes, the file name on Windows might be treated as a relative-path instead of an absolute-path.
This looks a lot like this question: Ant produces jsfl with backslashes instead of slashes
So, try using the pathconvert
task.
<pathconvert targetos="unix" property="fulltrainer.unix_dir">
<path location="${trainer.dir}"/>
</pathconvert>
<property name="cf.props" value="${trainer.dir}/properties/commonConfig.properties"/>
<echo file="${cf.props}" message="# KEY VALUE"/>
<echo file="${cf.props}" append="yes" message="CurrentBuildFile=${fulltrainer.unix_dir}/current_build"/>
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