2013-05-03 71 views
0

我INI該INI文件中獲取值(config.ini)文件看起來像下面如何可以解析和使用PowerShell

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

我怎樣才能使用PowerShell中的[Folder]內容?

我需要的文件夾路徑在數組

我見過的例子是與名稱值對

回答

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 
+0

感謝的作品,但如果我在失敗的ini文件中添加一個'[xxxxx]'。現在我只需要一個。因此接受了這個答案。感謝您的時間 – KK99 2013-05-03 11:14:54

+0

@KarthikKrishnan樂於幫助。如果有更多的[xxxx]使用'($ a.IndexOf(「[Folder]」)+ 1,($ a.IndexOf(「[xxxx]」) - $ a.indexof(「[Folder]」 )))' – 2013-05-03 11:22:23