更新ini文件时删除ant写入的ini文件中的注释 [英] Removing comment in ini file writen by ant when updating the ini file

查看:36
本文介绍了更新ini文件时删除ant写入的ini文件中的注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ant 文件,它更新 ant 文件中的数据,因为这个 ini 文件被更新,并且在顶部有如下注释

I have an ant file which updates the data in ant file due this ini file gets updated and at the top it has a comment as follows

#Thu, 07 Jul 2011 06:54:54 -0500

我不想要这个评论,因为我正在使用 parse_ini 通过 php 访问这个文件.由于这条评论,我失败了

I don't want this comment as i am accessing this file by php using parse_ini. Due to this comment i get an failure

Comments starting with '#' are deprecated in build.ini on line 1

所以有什么办法可以让我不会在ini文件中得到评论.

so is there any way so that i will not get the comment in ini file.

谢谢.

<propertyfile file="build.ini">
  <entry key="build-number" type="int" operation="+" value="1" />
</propertyfile>

这会通过 +1 更新我的 ini 文件内部版本号

this updates my ini file build-number by +1

推荐答案

Martin 的评论指出了一种使用 replaceregexp 删除评论的方法.(我正要向你展示一个类似的想法,但使用了 move、filterchain 和 striplinecomments.但是 replaceregexp 更紧凑.)

Martin's comment points you to a way to remove comments using replaceregexp. (I was about to show you a similar idea but using move, filterchain and striplinecomments. But the replaceregexp is more compact.)

我的另一个建议是,由于您正在编辑 ini 文件,也许您应该使用专门用于该文件的任务,而不是使用 PropertyFile 任务.ant-contrib 中有一个 IniFile 任务可能会完成这项工作.

The other suggestion I have is that since you are editing ini files, maybe you should use a task dedicated to that, rather than using the PropertyFile task. There is an IniFile taks in ant-contrib might do the job.

如果 replaceregexp 对您不起作用,因为您的文件中有其他 # 条注释,而您只想删除该第一行,请尝试以下操作:

If the replaceregexp doesn't work for you because your file has other # comments in it and you only want to remove that top line, then try this:

<target name="test">
  <propertyfile file="test.properties">
    <entry key="key" value="value"/>
  </propertyfile>
  <move file="test.properties" tofile="test.properties.tmp">
    <filterchain>
      <headfilter lines="-1" skip="1"/>
    </filterchain>
  </move>
  <move file="test.properties.tmp" tofile="test.properties"/>
</target>

输出:

$ cat test.properties
one=1
# existing comment

$ ant
Buildfile: C:\tmp\ant\build.xml

test:
[propertyfile] Updating property file: C:\tmp\ant\test.properties
     [move] Moving 1 file to C:\tmp\ant
     [move] Moving 1 file to C:\tmp\ant

BUILD SUCCESSFUL

Total time: 0 seconds

$ cat test.properties
one=1
# existing comment

key=value

这篇关于更新ini文件时删除ant写入的ini文件中的注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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