forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


delete ini file entry

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
thomas
Newbie


Joined: 15 Jan 2003
Posts: 23
Location: Germany

PostPosted: Wed Jan 21, 2004 11:45 am    Post subject: delete ini file entry Reply with quote

Hello,

I have a ini file like this:

[test]
test1=11223
test2=
Test3=5

Now I need to delete the parameter test2. So the follow ini are the result:

[test]
test1=11223
Test3=5

Does anybody know a solution with vds to do this?

Thanks!!
Back to top
View user's profile Send private message
CodeScript
Moderator Team


Joined: 08 Jun 2003
Posts: 1060
Location: India

PostPosted: Wed Jan 21, 2004 3:57 pm    Post subject: Reply with quote

Hi thomas
If you are using VDS 5 try this one (at your own risk)
Code:
#Define Function,WriteIniString

REM Syntax : @WriteIniString(<section name>,<key name to Delete>,<Ini File Name>)
%B = @WriteIniString(SectionOne,Test2,@PATH(%0)test.ini)
EXIT


REM You can include the code below in a seperate Unit:
:WriteIniString
LOADLIB KERNEL32
REM BOOL WritePrivateProfileString(
  REM LPCTSTR lpAppName,  // section name
  REM LPCTSTR lpKeyName,  // key name
  REM LPCTSTR lpString,   // string to add
  REM LPCTSTR lpFileName  // initialization file
REM );
%A = @LIB(KERNEL32,WritePrivateProfileStringA,int:,str:%1,str:%2,void:,str:%3)
FREELIB KERNEL32
EXIT %A


Save the below as test.ini in the same folder as above to test the script.
Code:

[SectionOne]

Test1=this is test line1
Test2=this is test line2


Key Test2 should be deleted if successful.

_________________
Regards
- CodeScript
Arrow Give your application a professional look with the VDSGUI Extension
Back to top
View user's profile Send private message Visit poster's website
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Wed Jan 21, 2004 3:59 pm    Post subject: Reply with quote

Hi Thomas,

Maybe you can just set the value of the key to nothing? That way, VDS won't recognize it, and will not be able to read the value (what will result into the same errormessage)... Smile

_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Back to top
View user's profile Send private message
jules
Professional Member
Professional Member


Joined: 14 Sep 2001
Posts: 1043
Location: Cumbria, UK

PostPosted: Wed Jan 21, 2004 4:02 pm    Post subject: Reply with quote

Windows does not, as far as I know, provide an API to do this.

Usually, it doesn't do any harm to leave an entry blank. If your use of INI files would leave a lot of blank entries, then the following routine should clean them up:

Code:
:CleanINIFile
  list create,31
  list loadfile,31,%%inipath
  if @ok()
    %I = 0
    while @greater(@count(31),%I)
      %D = @item(31,%I)
      %L = @len(%D)
      if @equal(@substr(%D,%L),=)
        list delete,31
      else
        %I = @succ(%I)
      end
    wend
    list savefile,31,%%inipath
  end
  list close,31
  exit


Note that the default value entry in @iniread() is returned only when the value does not exist, not when it exists but is blank. I have tripped up a few times because of this...

_________________
The Tech Pro
www.tech-pro.net
Back to top
View user's profile Send private message Visit poster's website
PGWARE
Web Host


Joined: 29 Dec 2001
Posts: 1565

PostPosted: Wed Jan 21, 2004 4:50 pm    Post subject: Reply with quote

You can load the inifile into a listbox, repeat through each item until the you find the @pos("test2=", LISTBOX) to be greater then 0, then simply delete the line from the listbox and save the file back to disk.

Code:

  list create,1
  list loadfile,1,INIFILE.INI
  if @greater(@count(1), 0)
    repeat
      if @greater(@pos("test2=", @item(1, @succ(@index(1)))), 0)
        list delete,1
      end
    until @equal(@succ(@index(1)), @count(1))
  end
  list savefile,1,INIFILE.INI
  list close,1
Back to top
View user's profile Send private message
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Wed Jan 21, 2004 6:27 pm    Post subject: Reply with quote

This should do the same... Smile

Code:
  list create,1
  list loadfile,1,INIFILE.INI
  while @match("test2=",1)
    list delete,1
  wend
  list savefile,1,INIFILE.INI
  list close,1

_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Back to top
View user's profile Send private message
FreezingFire
Admin Team


Joined: 23 Jun 2002
Posts: 3508

PostPosted: Wed Jan 21, 2004 6:57 pm    Post subject: Reply with quote

You can also use "xini.dll"...

Download: http://www.vdsworld.com/index.php?page=download&fileid=16

Description:

Quote:
This extension allows the deletion of keys and entire sections in INI files. Also a command to return all section names or values within a section.

_________________
FreezingFire
VDSWORLD.com
Site Admin Team
Back to top
View user's profile Send private message Visit poster's website
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2149
Location: A House

PostPosted: Wed Jan 21, 2004 8:36 pm    Post subject: Reply with quote

I usually just load the ini into a list, @match() the section name and then
the key name with the "=", and then delete that item in the list.

Code:

LIST CREATE,1
LIST LOADFILE,1,yourfile.ini
IF @text(1)
  LIST SEEK,1,0
  %A = @match([section],1)
  IF %A
    %A = @match(key=,1)
    IF %A
      LIST DELETE,1
      LIST SAVEFILE,1,yourfile.ini
    END
  END
END
LIST CLEAR,1
LIST CLOSE,1

_________________
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
Back to top
View user's profile Send private message
Dr. Dread
Professional Member
Professional Member


Joined: 03 Aug 2001
Posts: 1065
Location: Copenhagen, Denmark

PostPosted: Thu Jan 22, 2004 1:17 am    Post subject: Reply with quote

Garrett wrote:
I usually just load the ini into a list, @match() the section name and then
the key name with the "=", and then delete that item in the list.


If you do this, you gotta be sure that the INI does not have the same key name in another section -
or else you might end up deleting the wrong key if the right section does not have a key by that name
any more.

Perhaps something like this:
Code:

  %%inifile = yourfile.ini
  %%section = [section]
  %%keyname = yourkey

  LIST CREATE,1
  LIST LOADFILE,1,%%inifile
  if @match(1,%%section)
  %%increment = @next(1)
    repeat
      %%key = @item(1)
      if @equal(@substr(%%key,1,4),%%keyname"=")
        LIST DELETE,1
        %%found = yes
        LIST SAVEFILE,1,%%inifile
      else
        %%increment = @next(1)
      end
    until @equal(@pos("[",%%key),1)@equal(%%found,yes)
  end
  LIST CLOSE,1


BTW: I think you reversed your @match() parameters, Garrett Wink

Greetz
Dr. Dread

_________________
~~ Alcohol and calculus don't mix... Don't drink and derive! ~~

String.DLL * advanced string processing
Back to top
View user's profile Send private message
CodeScript
Moderator Team


Joined: 08 Jun 2003
Posts: 1060
Location: India

PostPosted: Thu Jan 22, 2004 3:47 am    Post subject: Reply with quote

jules wrote:
Windows does not, as far as I know, provide an API to do this.


msdn wrote:

WritePrivateProfileString
lpString
[in] Pointer 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.


I used the above API in my first reply to this post and here it
deletes the given key very well vds 5.01 on XP. Confused
Does it not work with others OR No one is interested in trying
that at all Rolling Eyes Sad
If definition of "solution with vds" does not include use of API then
that is a different thing.
BTW similar thing can be used to delete entire sections from ini file.

_________________
Regards
- CodeScript
Arrow Give your application a professional look with the VDSGUI Extension
Back to top
View user's profile Send private message Visit poster's website
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2149
Location: A House

PostPosted: Thu Jan 22, 2004 5:13 am    Post subject: Reply with quote

Dr. Dread wrote:
Garrett wrote:
I usually just load the ini into a list, @match() the section name and then
the key name with the "=", and then delete that item in the list.


If you do this, you gotta be sure that the INI does not have the same key name in another section -
or else you might end up deleting the wrong key if the right section does not have a key by that name
any more.

BTW: I think you reversed your @match() parameters, Garrett Wink

Greetz
Dr. Dread


I never name two keys the same name myself. But that's just me. And
as for the reverse, I probably did, as I just typed that off the top of my
head. Rolling Eyes

-Garrett

_________________
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group