다른 명령
잔글 개발노트 양식 일괄 적용 |
|||
| 1번째 줄: | 1번째 줄: | ||
{{개발노트 | |||
|요약=AutoIt에서 .ini 파일을 메모리에 로드해두고 필요할 때마다 읽어오는 방법은 IniRead 또는 IniReadSection 함수를 활용하여 파일의 내용을 변수에 저장하는 것임. | |||
|핵심= | |||
|분야=Autoit | |||
|작성일=2024-10-31 | |||
}} | |||
== Autoit ini파일 memory 캐시 == | == Autoit ini파일 memory 캐시 == | ||
* AutoIt에서 .ini 파일을 메모리에 로드해두고 필요할 때마다 읽어오는 방법은 IniRead 또는 IniReadSection 함수를 활용하여 파일의 내용을 변수에 저장하는 것임. | * AutoIt에서 .ini 파일을 메모리에 로드해두고 필요할 때마다 읽어오는 방법은 IniRead 또는 IniReadSection 함수를 활용하여 파일의 내용을 변수에 저장하는 것임. | ||
2026년 11월 12일 (목) 12:45 기준 최신판
DEVCAFE NOTE
AutoitAutoIt에서 .ini 파일을 메모리에 로드해두고 필요할 때마다 읽어오는 방법은 IniRead 또는 IniReadSection 함수를 활용하여 파일의 내용을 변수에 저장하는 것임.
KEY POINTS · 핵심 정리
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