|
-
June 8th, 2006, 02:23 AM
#1
how can i delete a row from ini file?
how can i delete a row from ini file?
thnaks in advance
peleg
-
June 8th, 2006, 08:08 AM
#2
Re: how can i delete a row from ini file?
Isn't an ini file just a text file (with file type 'ini') ?
Most lines end with HEX 0D0A (CR/LF)
Simplest way would be to -
Read each line one by one and write out to a new file all lines except the one(s) you don't want - At the end rename the files (make the old one .BAK)
However I have also seen other types of ini files which are definitely not pure text which would require a different approach depending on the contents of the file
-
June 8th, 2006, 09:03 AM
#3
Re: how can i delete a row from ini file?
You can use the WritePrivateProfileString to delete a specific line from an INI file:
From the API-Guide:
Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
· lpAppName
Points to a null-terminated string containing the name of the section to which the string will be copied. If the section does not exist, it is created. The name of the section is case-independent; the string can be any combination of uppercase and lowercase letters.
· lpKeyName
Points to the null-terminated string containing the name of the key to be associated with a string. If the key does not exist in the specified section, it is created. If this parameter is NULL, the entire section, including all entries within the section, is deleted.
· lpString
Points to a null-terminated string to be written to the file. If this parameter is NULL, the key pointed to by the lpKeyName parameter is deleted.
Windows 95: This platform does not support the use of the TAB (\t) character as part of this parameter.
· lpFileName
Points to a null-terminated string that names the initialization file.
Of course, if you're not using an INI file you've created (or that has been created in a similar fashion), you will probably have to read it in line by line and just not rewrite the line you want to remove.
-
June 12th, 2006, 03:52 AM
#4
Re: how can i delete a row from ini file?
-
June 12th, 2006, 07:55 AM
#5
Re: how can i delete a row from ini file?
Maybe this will help.
' to delete a setting
' [Section_Name] without the backets
' key_name= without the equal sign. If this is replaced
' with vbNullString then the whole section will be deleted.
' key_value to delete, replace with vbNullString
' full path and name of your ini file
lngRetCode = WritePrivateProfileString("section_name", "key_name", _
"key_value", "C:\folder_name\ini_file.ini")
Happy coding
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|