Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do generate a directory path with double-backslash or forward-slash separators?

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?

like image 813
mainstringargs Avatar asked Oct 05 '10 13:10

mainstringargs


People also ask

What does double backslash mean in file path?

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.

Are file path forward or backward slash?

Windows traditionally uses the backslash ( \ ) to separate directories in file paths. (For example, C:\Program Files\PuppetLabs .)

Should directory path ends with slash?

It is expected that a directory not end in a slash. Any expectation that a directory ends in a slash is wrong.

Does Linux use backslash or forward slash?

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.


1 Answers

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"/>
like image 191
Andy Avatar answered Sep 20 '22 06:09

Andy