解析一个.ini文件(Parsing a .ini file)

2019-08-03 09:26发布

我的问题是有关分析ini文件在Windows命令行。

而试图删除与文件中的所有密钥的部分我被困。 本节的名称是已知的,保存在一个变量。

我试图挽救线(开始,结束)之间取出的东西,但它并没有为我工作。

这里有人能帮助我吗?

编辑:

下面是一个例子ini文件:

[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

Answer 1:

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

你可以检查这是否会做的工作?

编辑:这不是测试:

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
) 


文章来源: Parsing a .ini file