Вот функция которую я когда то писал для обработки ключей в файлах *.properties:
Код:
#include <Array.au3>
_FilePropertyWrite("File.properties", "Scripts", "MyScript.au3|SomeScript1.au3|SomeScript2.au3|SomeScript3.au3")
$aProperty = _FilePropertyRead("File.properties", "Scripts", "", 1)
_ArrayDisplay($aProperty)
Func _FilePropertyRead($sFile, $sProperty, $sDefault = "", $iRetArr = 1)
Local $aFileRead = StringSplit(StringStripCR(FileRead($sFile)), @LF)
Local $sRet, $sPattern = '(?i)^\s*\Q' & $sProperty & '\E\s*=\s*'
For $i = 1 To $aFileRead[0]
If StringRegExp($aFileRead[$i], $sPattern) Then
$aFileRead[$i] = StringRegExpReplace($aFileRead[$i], $sPattern, '')
If StringRight($aFileRead[$i], 1) = "\" Then
$aFileRead[$i] = StringTrimRight($aFileRead[$i], 1)
EndIf
$sRet &= StringStripWS($aFileRead[$i], 3)
For $j = $i+1 To $aFileRead[0]
If StringInStr($aFileRead[$j], "=") Then
ExitLoop 2
ElseIf StringLeft(StringStripWS($aFileRead[$j], 1), 1) <> "#" Then
If StringRight($aFileRead[$j], 1) = "\" Then
$aFileRead[$j] = StringTrimRight($aFileRead[$j], 1)
EndIf
$sRet &= " " & StringStripWS($aFileRead[$j], 3)
EndIf
Next
ExitLoop
EndIf
Next
If $sRet == "" Then
$sRet = $sDefault
Else
$sRet = StringStripWS($sRet, 3)
EndIf
If $iRetArr Then
Return StringSplit($sRet, " ")
EndIf
Return $sRet
EndFunc
Func _FilePropertyWrite($sFile, $sProperty, $sValue, $iInsInLine = -1, $iPropsPerLine = 5)
Local $aFileRead = StringSplit(StringStripCR(FileRead($sFile)), @LF)
Local $sPropPattern = '(?i)^\s*(\Q' & $sProperty & '\E)\s*=\s*.*'
Local $sKeyPattern = '^\s*([^=]+\s*=\s*|#)'
Local $hFile, $sFileContent, $aValue, $sLine, $iPropFound = 0
$aValue = StringSplit(StringReplace($sValue, '\', ''), '|')
$sValue = ''
For $i = 1 To $aValue[0]
$sValue &= $aValue[$i]
If $i < $aValue[0] Then
If $i = 1 Or Mod($i - 1, $iPropsPerLine) = 0 Then
$sValue &= ' \' & @CRLF & @TAB
Else
$sValue &= ' '
EndIf
EndIf
Next
For $i = 1 To $aFileRead[0]
$sLine = $aFileRead[$i]
If StringRegExp($aFileRead[$i], $sPropPattern) Then
If $iInsInLine = -1 Then
$iPropFound = 1
$sLine = StringRegExpReplace($aFileRead[$i], $sPropPattern, '\1=' & StringReplace($sValue, '\', '\\'))
EndIf
For $j = $i+1 To $aFileRead[0]
If StringRegExp($aFileRead[$j], $sKeyPattern) Or $i >= $aFileRead[0] Then
ExitLoop
EndIf
$i += 1
Next
If $iInsInLine <> -1 Then
ContinueLoop
EndIf
EndIf
$sFileContent &= $sLine
If $i < $aFileRead[0] Then
$sFileContent &= @CRLF
EndIf
Next
If $iInsInLine <> -1 Then
$aFileRead = StringSplit(StringStripCR($sFileContent), @LF)
$sFileContent = ''
For $i = 1 To $aFileRead[0]
If $i = $iInsInLine Then
$iPropFound = 1
$sFileContent &= $sProperty & "=" & $sValue & @CRLF & $aFileRead[$i]
Else
$sFileContent &= $aFileRead[$i]
EndIf
If $i < $aFileRead[0] Then
$sFileContent &= @CRLF
EndIf
Next
EndIf
If Not $iPropFound Then
If $sFileContent <> '' And StringRight($sFileContent, 2) <> @CRLF Then
$sFileContent &= @CRLF
EndIf
$sFileContent &= $sProperty & "=" & $sValue
EndIf
$hFile = FileOpen($sFile, 2)
FileWrite($hFile, $sFileContent)
Return FileClose($hFile)
EndFunc
работает также с многострочными значениями (разделённые слешем «\»).