【问题标题】:How can I parse and get values from this INI file using Powershell如何使用 Powershell 解析并从此 INI 文件中获取值
【发布时间】:2013-05-03 09:15:12
【问题描述】:

我的 INI (config.ini) 文件如下所示

#this is comment
[Folder]
C:\temp
C:\dir1
C:\dir2

如何使用powershell获取[Folder]的内容?

我需要数组中的文件夹路径

我看到的例子是名称值对

【问题讨论】:

    标签: powershell


    【解决方案1】:

    使用您的示例 config.ini:

    [System.Collections.ArrayList]$a = GC .\CONFIG.INI
    [string[]]$b=$a.GetRange( $a.IndexOf("[Folder]")+1, ( $a.Count - ($a.IndexOf("[Folder]")+1)))
    $b
    C:\temp
    C:\dir1
    C:\dir2
    

    【讨论】:

    • 感谢工作,但如果我在 ini 文件中再添加一个 [xxxxx] 它将失败。现在我只需要一个。因此接受这个答案。感谢您的宝贵时间
    • @KarthikKrishnan 很高兴为您提供帮助。如果有更多 [xxxx] 用($a.IndexOf("[Folder]")+1, ( $a.IndexOf("[xxxx]") - $a.indexof("[Folder]")))修复范围@
    猜你喜欢
    • 1970-01-01
    • 2010-09-29
    • 2011-09-04
    • 2017-12-16
    • 1970-01-01
    • 1970-01-01
    • 2021-02-28
    • 2023-04-03
    • 1970-01-01
    相关资源
    最近更新 更多