解析.ini文件 [英] Parsing a .ini file

查看:217
本文介绍了解析.ini文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是关于使用windows命令行解析ini文件。



我试图从文件中删除所有关键字的节。



我试图保存行(开始,结束)以删除之间的东西,但它does not为我工作。



谁能帮助我?



编辑 >

这里是一个ini文件示例:

  [示例] 
cycle = value
cycle2 = value
cycle_bu = value

[Example2]
key1 = value
key2 = value
key3 = value
key4 = value

[something3]
key1 = value
key2 = value
key3 = value
key4 = value
key5 = value
key6 = value


解决方案

http://www.robvanderwoude.com/sourcecode.php?src=readini_nt



编辑:
b这未经测试:

  break> new.ini 
set skip_this_section = [something]
set skip_flag = 0
for / f %% I in(myini.ini)do(
call:print_to_file %% I

goto:eif

:print_to_file
setlocal enabledelayedexpansion
set line =%1
set first_char =!line:〜0,1!
if!first_char! EQU[
if!line!EQU!skip_this_section!(
设置skip_flag = 1
)else(
设置skip_flag = 0


endlocal& set skip_flag =%skip_flag%
if%skip_flag%EQU%0%(
echo%1>> new.ini


My question is about parsing an ini file with the windows command line.

I stucked while trying remove a section with all keys from the file. The name of this section is known and saved in a varible.

I tried to save the lines (start, end) for removing the stuff between but it doesnt worked for me.

Anyone here who can help me?

edit:

here is an example ini file:

[Example]
cycle = value
cycle2 = value
cycle_bu = value

[Example2]
key1 = value
key2 = value
key3 = value
key4 = value

[something3]
key1 = value
key2 = value
key3 = value
key4 = value
key5 = value
key6 = value

解决方案

http://www.robvanderwoude.com/sourcecode.php?src=readini_nt

Could you check if this will do the work?

EDIT: this is not tested:

break >new.ini
set skip_this_section=[something]
set skip_flag=0
for /f  %%I in (myini.ini) do (
   call :print_to_file %%I
)
goto :eif

:print_to_file
setlocal enabledelayedexpansion 
    set line=%1
    set first_char=!line:~0,1!
    if "!first_char!" EQU "[" (
        if "!line!" EQU "!skip_this_section!" (
           set skip_flag=1
        ) else (
           set skip_flag=0
        )
    )
endlocal & set skip_flag=%skip_flag%
if %skip_flag% EQU %0% (
   echo %1 >> new.ini
) 

这篇关于解析.ini文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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