如何生成带有双反斜线或正斜杠分隔的目录路径? [英] How do generate a directory path with double-backslash or forward-slash separators?

查看:178
本文介绍了如何生成带有双反斜线或正斜杠分隔的目录路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写的目录路径,从蚂蚁的文本文件,该文件后来由Java应用程序读取找到另一个文件。

I am writing a directory path to a text file from ant, which is later read by a Java Application to find another file.

在我的ant脚本我有:

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>

在build.properties文件trainer.dir设置为:

in the build.properties file trainer.dir is set to:

trainer.dir=../trainer

它结束了写:

# KEY        VALUE
CurrentBuildFile=C:\Workspaces\ralph\trainer\current_build

到commonConfig.properties文件。

to the commonConfig.properties file.

我需要它写:

# 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?

推荐答案

这看起来很像这个问题:<一href=\"http://stackoverflow.com/questions/1799684/ant-basedir-slashes-escape-problem\">http://stackoverflow.com/questions/1799684/ant-basedir-slashes-escape-problem

This looks a lot like this question: http://stackoverflow.com/questions/1799684/ant-basedir-slashes-escape-problem

所以,尽量使用 pathconvert 任务。

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"/>

这篇关于如何生成带有双反斜线或正斜杠分隔的目录路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆