Previous Topic: DeleteIniEntry - Remove an Entry in an Initialization FileNext Topic: ReadIniSection - Retrieve a Section


DeleteIniSection - Remove a Section in an Initialization File

Valid on UNIX platforms

The DeleteIniSection function removes an entire section in the specified initialization (.ini) file.

Function format:

DeleteIniSection(section as String, filename as String) as Boolean
section

Identifies the section to delete.

filename

Indicates the name of the initialization (.ini) file.

On successful completion, the function returns TRUE; otherwise, returns FALSE.

Example:

This example reads from the file c:\temp\test.ini, the section LIST and from the section SINGLE the entry Entry, and prints them. The example deletes the section LIST and the entry Entry from the section SINGLE.

Function strTok(in As string, BYREF pos As Integer, token As String, BYREF out As String) As Boolean
	Dim buf As String
	Dim len As Integer

	If (pos > Len(in)) Then
		strTok = FALSE
	Else
		buf = Mid(in, pos)
		len = Instr(buf, token)
		If len = 0 Then
			out = buf
			pos = pos + Len(buf) + 1
		Else
			out = Mid(buf, 0, len-1)

pos = pos + len + 1
		End If
		strTok = TRUE
	End If
End Function

Dim attrList, str, lf As string
Dim pos As Integer

' clear screen
ClrScr()

If Not(ReadIniSection("LIST", attrList, "c:\temp\test.ini")) Then
	MessageBox("Can not read LIST section", "DMS", MB_OK + MB_ICONEXCLAMATION)
	SetStatus(1)
	Exit
End If
Print("[LIST]")
pos = 0
lf = chr(10)
While (strTok(attrList, pos, lf, str))
	Print(str)
Wend

If Not(ReadIniEntry("SINGLE", "Entry", attrList, "c:\temp\test.ini")) Then

MessageBox("Can not read SINGLE section", "DMS", MB_OK + MB_ICONEXCLAMATION)
	SetStatus(2)
	Exit
End If

Print("[SINGLE]" + NEWLINE$ + "Entry=" + attrList)

If Not(DeleteIniEntry("SINGLE", "Entry", "c:\temp\test.ini")) Then
	MessageBox("Can not delete [SINGLE].Entry ", "DMS", MB_OK + MB_ICONEXCLAMATION)
	SetStatus(3)
	Exit
End If
If Not(DeleteIniSection("LIST", "c:\temp\test.ini")) Then
	MessageBox("Can not delete LIST section", "DMS", MB_OK + MB_ICONEXCLAMATION)

SetStatus(4)
	Exit
End If