代码之家  ›  专栏  ›  技术社区  ›  mainstringargs

如何生成带有双反斜杠或正斜杠分隔符的目录路径?

  •  6
  • mainstringargs  · 技术社区  · 14 年前

    在我的蚂蚁脚本中我有:

    <property name="fulltrainer.dir"  location="${trainer.dir}" />
    
    <echo file="${trainer.dir}/properties/commonConfig.properties"># KEY         VALUE
    CurrentBuildFile=${fulltrainer.dir}\current_build</echo>
    

    在生成.属性文件培训师.dir设置为:

    trainer.dir=../trainer
    

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

    致commonConfig.properties属性文件。

    我需要它来写:

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

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

    我怎么能做到呢?

    1 回复  |  直到 14 年前
        1
  •  9
  •   Community leo1    7 年前

    这看起来很像这个问题: Ant produces jsfl with backslashes instead of slashes

    所以,试着用 pathconvert 任务。

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