gpt4 book ai didi

ant - 如何使用 ant replaceregex 任务在 Windows 中用文件路径替换一行?

转载 作者:行者123 更新时间:2023-12-01 23:24:49 25 4
gpt4 key购买 nike

在我的构建文件中,我有一个 ant 目标,其中有以下代码片段,

 <replaceregexp replace="custom.dir=${basedir}/tasks/custom" byline="true" file="${basedir}/MyApp/configuration.properties">
<regexp pattern="custom.dir=(.*)"/>
</replaceregexp>

我想用“configuration.properties”文件中的路径替换“custom.dir”属性,但是一旦我执行了我的目标,我就将“custom.dir”属性的条目修改为

custom.dir=c:arenaplaygroundmytestapp/tasks/custom

代替

custom.dir=c:\arena\playground\mytestapp/tasks/custom

我应该怎么做才能使用正确的文件分隔符将路径正确写入“configuration.properties”文件。我在 windows 上使用的 ant 是 ant 1.8 。

最佳答案

当您尝试将 WINDOW_STYLE_PATH 写入文件时,WINDOW_FILE_SEPARATOR 被识别为转义序列字符。所以你可以在将它写入文件之前更改 unix 样式的路径。 Pathconvert 将协助您转换路径...

<pathconvert property="new" dirsep="/">
<path location="${basedir}"/>
</pathconvert>
<echo message="${new}"/>
<replaceregexp replace="custom.dir=${new}/tasks/custom" byline="true" file="${basedir}/configuration.properties">
<regexp pattern="custom.dir=(.*)"/>
</replaceregexp>

关于ant - 如何使用 ant replaceregex 任务在 Windows 中用文件路径替换一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13581258/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com