본문 바로가기
자기계발/AHK

[AHK v2] ini 파일 사용하기 (iniWrite, iniRead, iniDelete)

by HibiscusT 2025. 2. 23.

/*
	IniWrite : ini 파일 쓰기
	IniDelete : ini 파일 삭제하기
	IniRead : ini 파일 읽기
*/

inifilepath := A_ScriptDir . "\test.ini"

; IniWrite(쓸 내용, ini파일 경로, 섹션, 키)
; 키 있으면 큐 형태로 저장 /  키 없으면 스택 형태로 저장
IniWrite("value1", inifilepath, "section1" , "key1")
IniWrite("value2", inifilepath, "section1" , "key2")
IniWrite("value3", inifilepath, "section2")
IniWrite("value4", inifilepath, "section2")
; IniWrite("value5", inifilepath) ; 섹션 없으면 error

 

 

; IniRead(ini파일 경로, 섹션, 키, 기본값)
value1 := IniRead(inifilepath)
value2 := IniRead(inifilepath, "section1")
value3 := IniRead(inifilepath, "section1", "key1")
msgbox value1
msgbox value2
msgbox value3

; IniDelete(ini파일 경로, 섹션, 키)
IniDelete(inifilepath, "section1", "key1") ; 키에 해당하는 값 제거
IniDelete(inifilepath, "section2") ; 섹션 통으로 제거

; 응용

inifilepath := A_ScriptDir . "\test.ini"

arr := Array()
Loop 5
{
	arr.Push("value" . A_Index)
}

Loop arr.Length
{
	;IniWrite(arr.Pop(), inifilepath, "section1", "key" . (arr.Length + 1))
	IniWrite(arr.RemoveAt(1), inifilepath, "section1", "arr2[" . A_Index . "]")
}

arr2 := StrSplit(IniRead(inifilepath, "section1"), "`n")
Loop arr2.Length
{
	msgbox arr2[A_Index]
}

'자기계발 > AHK' 카테고리의 다른 글

[AHK v2] AutoHotkey 설치 및 환경 셋팅  (0) 2025.02.12