다른 명령
새 문서: == Autoit ini파일 memory 캐시 == * AutoIt에서 .ini 파일을 메모리에 로드해두고 필요할 때마다 읽어오는 방법은 IniRead 또는 IniReadSection 함수를 활용하여 파일의 내용을 변수에 저장하는 것임. * .ini 파일 전체를 메모리에 올려두려면 IniReadSectionNames와 IniReadSection 함수 사용 * ini 파일의 내용을 메모리에 저장해두면, 파일을 매번 다시 읽지 않고도 데이터를 손쉽게 접근. === .i... |
|||
| (같은 사용자의 중간 판 3개는 보이지 않습니다) | |||
| 18번째 줄: | 18번째 줄: | ||
==== .ini 파일을 메모리에 로드하고 읽기 ==== | ==== .ini 파일을 메모리에 로드하고 읽기 ==== | ||
<source lang= | <source lang=autoit> | ||
#include <Array.au3> | |||
#include <MsgBoxConstants.au3> | |||
Global $g_Config = _ReadIniToMemory("config.ini") | |||
Global $ | |||
; | ; 예시 조회 | ||
Func | MsgBox(0, "MYKEY", _GetConfig("username", "username")) | ||
MsgBox(0, "FONT_NAME", _GetConfig("Network", "ip")) | |||
If Not | |||
; ============================ | |||
; INI 읽고 메모리에 저장하는 함수 | |||
Func _ReadIniToMemory($sFilePath) | |||
Local $config = ObjCreate("Scripting.Dictionary") | |||
If Not FileExists($sFilePath) Then | |||
MsgBox(16, "오류", "INI 파일을 찾을 수 없습니다: " & $sFilePath) | |||
Exit | |||
EndIf | EndIf | ||
If | Local $sections = IniReadSectionNames($sFilePath) | ||
If @error Then Return $config | |||
For $i = 1 To $sections[0] | |||
Local $section = $sections[$i] | |||
Local $keyValues = IniReadSection($sFilePath, $section) | |||
If @error Then ContinueLoop | |||
Local $innerDict = ObjCreate("Scripting.Dictionary") | |||
For $j = 1 To $keyValues[0][0] | |||
$innerDict.Add($keyValues[$j][0], $keyValues[$j][1]) | |||
Next | |||
$config.Add($section, $innerDict) | |||
Next | |||
Return $config | |||
EndFunc | EndFunc | ||
; | ; 설정값을 조회하는 함수 | ||
Func _GetConfig($sSection, $sKey) | |||
If Not $g_Config.Exists($sSection) Then Return "" | |||
Local $ | Local $sectionDict = $g_Config.Item($sSection) | ||
If Not $sectionDict.Exists($sKey) Then Return "" | |||
Return $sectionDict.Item($sKey) | |||
EndFunc | |||
</source> | </source> | ||
[[category:autoit]] | |||
2025년 7월 28일 (월) 22:46 기준 최신판
Autoit ini파일 memory 캐시
- AutoIt에서 .ini 파일을 메모리에 로드해두고 필요할 때마다 읽어오는 방법은 IniRead 또는 IniReadSection 함수를 활용하여 파일의 내용을 변수에 저장하는 것임.
- .ini 파일 전체를 메모리에 올려두려면 IniReadSectionNames와 IniReadSection 함수 사용
- ini 파일의 내용을 메모리에 저장해두면, 파일을 매번 다시 읽지 않고도 데이터를 손쉽게 접근.
.ini 파일을 메모리에 로드한 후 필요할 때마다 데이터를 불러오는 방법
.ini 파일 예시
- 예를 들어 config.ini 파일이라고 가정
[Settings] username=admin password=1234 [Network] ip=192.168.1.1 port=8080
.ini 파일을 메모리에 로드하고 읽기
#include <Array.au3>
#include <MsgBoxConstants.au3>
Global $g_Config = _ReadIniToMemory("config.ini")
; 예시 조회
MsgBox(0, "MYKEY", _GetConfig("username", "username"))
MsgBox(0, "FONT_NAME", _GetConfig("Network", "ip"))
; ============================
; INI 읽고 메모리에 저장하는 함수
Func _ReadIniToMemory($sFilePath)
Local $config = ObjCreate("Scripting.Dictionary")
If Not FileExists($sFilePath) Then
MsgBox(16, "오류", "INI 파일을 찾을 수 없습니다: " & $sFilePath)
Exit
EndIf
Local $sections = IniReadSectionNames($sFilePath)
If @error Then Return $config
For $i = 1 To $sections[0]
Local $section = $sections[$i]
Local $keyValues = IniReadSection($sFilePath, $section)
If @error Then ContinueLoop
Local $innerDict = ObjCreate("Scripting.Dictionary")
For $j = 1 To $keyValues[0][0]
$innerDict.Add($keyValues[$j][0], $keyValues[$j][1])
Next
$config.Add($section, $innerDict)
Next
Return $config
EndFunc
; 설정값을 조회하는 함수
Func _GetConfig($sSection, $sKey)
If Not $g_Config.Exists($sSection) Then Return ""
Local $sectionDict = $g_Config.Item($sSection)
If Not $sectionDict.Exists($sKey) Then Return ""
Return $sectionDict.Item($sKey)
EndFunc