microbious Posted June 15, 2009 Share Posted June 15, 2009 i am trying to come up with text file reader that will read whole text file and if it finds line where it says: Level=? (where ? has to vary from min to max value, maybe like from 10 to 100) So if Level= value of minimum 10 and max 100 then not just erase this line but go up the text file untill empty line is found and then sellect everything till next empty line found and then erase it all Here is an example of what it would do. DOC: -------------------------------- something else here something else here Level=200 something else here something else here something else here something else here Level=50 something else here something else here something else here something else here Level=200 something else here something else here something else here something else here Level=30 something else here something else here ----------------------------------------- So i would need it to erase Level=50 and Level=30 including all of the 'something else here' lines but not erase others. I understand that i need to come up with something tricky here but i am not sure how. Please point me to the right direction. Thanks Link to comment Share on other sites More sharing options...
bo8ster Posted June 15, 2009 Share Posted June 15, 2009 StringRegExp will help you find 'Level' I would use something like FileReadLine in a loop to read the file.=. If you want to change text in the file then FileWriteLine is the way to go. Have a look FileOpen to make sure you overwrite not append. Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic] Link to comment Share on other sites More sharing options...
microbious Posted June 15, 2009 Author Share Posted June 15, 2009 any examples ? Link to comment Share on other sites More sharing options...
Sundance Posted June 15, 2009 Share Posted June 15, 2009 Or do a fileread and a while EOF / wend loop to go through every line of the array. Set a spacepopinter variable to 0 Look in the actual line for your Level=x and an the empty line. If the current line is empty save the line number to the spacepointer variable. If you found your level=x then delete every line between spacepointer and the current line proceed wiithin the while loop... Link to comment Share on other sites More sharing options...
bo8ster Posted June 15, 2009 Share Posted June 15, 2009 any examples ?I don't have any examples - the help file has some for the file stuff. Give it a shot, i'm sure you can work it out, post code when u get stuck Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic] Link to comment Share on other sites More sharing options...
microbious Posted June 15, 2009 Author Share Posted June 15, 2009 spacepopinter variable to 0 proceed wiithin the while loop ? makes no sense to noob like me thats why i asked for example. Thanks anyway. Link to comment Share on other sites More sharing options...
Developers Jos Posted June 15, 2009 Developers Share Posted June 15, 2009 spacepopinter variable to 0proceed wiithin the while loop?makes no sense to noob like me thats why i asked for example.Thanks anyway.You are here long enough to know how things work here so give it a start and come back when you have something to show. SciTE4AutoIt3 Full installer Download page  - Beta files    Read before posting   How to post scriptsource   Forum etiquette Forum Rules  Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
microbious Posted June 15, 2009 Author Share Posted June 15, 2009 (edited) yes i am for a while now but the thing with this one is that i dont even know what to start with. I dont need GUI at this moment, all i need is a head start of some sort. Its just that this is something i cant think of anything that would make it work. Dam i cant even think how to start the code. Here is an example of what this thing would look like. $section = there is no way to tell, it can be anything $key = 10 min and 100 max value $read = iniread ('file.ini',$section,$key) If $read = 1 Then IniDelete ('file.ini',$section,$key) Else EndIf And this is puled out from that INI file: [[DI]3rddestroyer RPGPlayerDataObject] OwnerID=9b7b732d6b415bcc Level=238 [mat301 RPGPlayerDataObject] OwnerID=Bot Level=300 [jake13 RPGPlayerDataObject] OwnerID=b61adedab28b7f4 Level=102 [C RPGPlayerDataObject] OwnerID=7ae430e4043e7d Level=154 This ini has 100's of users so i need it to keep looking for more that match to $section and $key Only 2 things i need code to figure out If OwnerID=Bot and if Level=min 10 or max 100 If any of these match then remove section in which those were found. Removing whole section is exactly what i need but i find it impossible for me to figure out how to create $vas's that will help me figure out variations that i could use. In other words, if section has level variation i would specify then it should delete the section or if the section has Bot in it, then delete it as well. Please help me out guys Edited June 16, 2009 by lessstoopid Link to comment Share on other sites More sharing options...
Skruge Posted June 16, 2009 Share Posted June 16, 2009 First off, you didn't mention it was an INI file. That changes everything.there is no way to tell, it can be anythingThe function you need is INIReadSectionNames. [font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font] Link to comment Share on other sites More sharing options...
microbious Posted June 16, 2009 Author Share Posted June 16, 2009 (edited) $var= IniReadSectionNames ("ut2004rpg.ini") MsgBox(4096, "", $var) shows me no messages so i looked into IniReadSectionNames help file. $var = IniReadSectionNames(@WindowsDir & "\win.ini") If @error Then MsgBox(4096, "", "Error occurred, probably no INI file.") Else For $i = 1 To $var[0] MsgBox(4096, "", $var[$i]) Next EndIf works but i dont understand use of For $i = 1 To $var[0] Edited June 16, 2009 by lessstoopid Link to comment Share on other sites More sharing options...
Skruge Posted June 16, 2009 Share Posted June 16, 2009 INIReadSectionNames returns an array, which is why you can't display it in MsgBox the way you tried.The first element of the array ($var[0]) contains the amount of sections it read, so that for loop acts on every member of the array. [font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font] Link to comment Share on other sites More sharing options...
microbious Posted June 16, 2009 Author Share Posted June 16, 2009 (edited) help me understand where do i put variations that i am looking for in the ini ? $var = IniReadSectionNames ('ut2004rpg.ini') If @error Then MsgBox(4096, "", "Error occurred, probably no INI file.") Else For $i = 1 To $var[0] MsgBox(4096, "", $var[$i]) Next EndIf All i know is that if i change 1 to 2 it will start from second section. I do not understand use of $var[0] at all, all i know is that $var is just a name that can be referenced to later in the script. I would think that this would work $var = IniReadSectionNames ('ut2004rpg.ini') $varlevel = iniread ('ut2004rpg.ini', $var, 'key') $varOwnerID= 'Bot' If $varlevel = $var Then IniDelete ('ut2004rpg.ini',$var,'') Else look into next section ? EndIf but it doesnt. my knowledge is very limited and i know this code dont make sense much but thats all i can think of. Thanks for trying to help Edited June 16, 2009 by lessstoopid Link to comment Share on other sites More sharing options...
Skruge Posted June 16, 2009 Share Posted June 16, 2009 I do not understand use of $var[0] at all, all i know is that $var is just a name that can be referenced to later in the script.Your homework is to study arrays. Start with the help file entry that I linked in my last post, and test out the example for _ArrayDisplay. Local $iLevel, $sOwner Local $sINIFile = "ut2004rpg.ini" Local $aSections = IniReadSectionNames($sINIFile) If @error Then MsgBox(4096, "", "Error occurred, probably no INI file.") Else For $iX = 1 To $aSections[0] $sOwner = IniRead($sINIFile, $aSections[$iX], "OwnerID") $iLevel = IniRead($sINIFile, $aSections[$iX], "Level") If ($sOwner = "Bot") And (($iLevel >= 10) And ($iLevel <= 100)) Then ConsoleWrite("Deleting " & $aSections[$iX] & @CRLF) IniDelete($sINIFile, $aSections[$iX]) Else ConsoleWrite("Skipped " & $aSections[$iX] & @CRLF) EndIf Next EndIf [font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font] Link to comment Share on other sites More sharing options...
microbious Posted June 16, 2009 Author Share Posted June 16, 2009 (edited) your example starting to make sense to me THANKS 1 problem is that it wont execute due to wront number of arguments for $sOwner = IniRead ($sINIFile, $aSections[$iX], "OwnerID") $iLevel = IniRead ($sINIFile, $aSections[$iX], "Level") But it seems to me that its all good. Maybe i should attach the INI file so u can look at it and see what it made of if u want (if u have time). Thanks I translated array to my language and it still dont make much sense to me but i begin to understand better now thanks to you. My logic with programing based on simple concepts such as once used in CMD but i work hard to learn. Edited June 16, 2009 by lessstoopid Link to comment Share on other sites More sharing options...
microbious Posted June 16, 2009 Author Share Posted June 16, 2009 (edited) Dude your example is so great !!! i started to rewrite it step by step altering some things and i start to understand the use of 'For' Man thanks allot. WORKING............................. Please someone look into my code and tell me why removed sections of INI are left empty line behind them ? INI is getting cleaned up but it has to much empty lines. Also for some reasons not all specified in range entry's are removed, even BOT is left behind somehow . expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> FileInstall ('RPGLOGO.jpg', @TempDir & '/RPGLOGO.jpg') #Region;GUI GUICreate ("Clean RPG",376,200) GUISetState() #EndRegion #Region; unput local $level, $OwnerID,$IDcheck,$X,$B,$log local $Filename = ("UT2004RPG.ini") local $Section = IniReadSectionNames ($filename) GUICtrlCreatePic (@TempDir & '/RPGLOGO.jpg',0,0,376,100) GUICtrlCreateLabel ("Set Player's level's",5,103) $log = GUICtrlCreateEdit ($log,100,100,276,100) $LOWlevelinput = GUICtrlCreateInput ('1',0,120,50,20) $HIGHlevelinput = GUICtrlCreateInput ('9999999',50,120,50,20) $Blevels = GUICtrlCreateButton ("Remove players",0,140,100,20) $BBots = GUICtrlCreateButton ("Remove Bot's",0,160,100,20) #EndRegion While 1 $nMsg = GUIGetMsg() Switch $nMsg case $Blevels $LOWlevelvalue = GUICtrlRead ($LOWlevelinput) $HIGHlevelvalue = GUICtrlRead ($HIGHlevelinput) If $Section > @error Then MsgBox (0,'ERROR','UT2004RPG.ini not found') Else For $X = 1 to $Section[0] $level = IniRead ($filename,$Section[$X],'Level','') If (($level >= $LOWlevelinput) and ($level <= $HIGHlevelvalue)) Then GUICtrlSetData ($log, 'Removed '& $Section[$X] & @CRLF) IniDelete ($filename,$Section[$X]) ;MsgBox (0,'','User '& $Section[$X] & ' Removed') IniDelete ($filename,$Section,'') EndIf If ($level = 1) then IniDelete ($filename,$Section[$X]) EndIf Next EndIf Case $BBots If $Section > @error Then MsgBox (0,'ERROR','UT2004RPG.ini not found') Else For $B = 1 to $Section[0] $Bot = IniRead ($filename,$Section[$B],'OwnerID','') If ($Bot = "Bot") Then IniDelete ($filename,$Section[$B],'') MsgBox (0,'','Bot '& $Section[$B] & ' Removed') EndIf Next EndIf Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd I attached image and ini file to make it eazier. Thanksscript.zip Edited June 16, 2009 by lessstoopid Link to comment Share on other sites More sharing options...
Skruge Posted June 16, 2009 Share Posted June 16, 2009 Glad to hear it. (Checking out that RPG mod) [font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font] Link to comment Share on other sites More sharing options...
microbious Posted June 17, 2009 Author Share Posted June 17, 2009 Thanks, i cant wait for your reply to say what i did wrong. (that is if i understood you correct) Link to comment Share on other sites More sharing options...
Skruge Posted June 17, 2009 Share Posted June 17, 2009 Thanks, i cant wait for your reply to say what i did wrong. (that is if i understood you correct) Looks good, mostly. IniDelete ($filename,$Section,'')This is no good because the array is missing its element, and the '' would cause it to remove a null value, not the whole section. Doesn't matter because it's deleted correctly two lines prior. IniDelete ($filename,$Section[$B],'')Similar to above, remove the empty quotes and you're good to go. The bigger issue though is the size of the file. Because of the underlying API, the INI functions are limited to 32K. See here for more info: http://www.autoitscript.com/forum/index.php?showtopic=33031 http://www.autoitscript.com/trac/autoit/ticket/15 There are some workarounds there... I'll see what I can come up with. [font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font] Link to comment Share on other sites More sharing options...
microbious Posted June 17, 2009 Author Share Posted June 17, 2009 (edited) Limited ? OH NO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! So is it like 32 characters max in each section ?So its lke if section name is longer then 32 characters it will not be read ? i was reading these posts u sent but didnt really get it. I have no words to express how i feel about you helping me out so ill try to use emoticons instead. i wish they had more Anyway i removed those ,'' in the inidelete and it worked, bot that was left behind is no longer exist. So here is a way i think could be worked around the problem with the INI 32k limit As you can see i have a case for each button pressed right ? So what if this button's case would have additional command that would right after removing section would remove 1 line that goes after that section ? Is that even possible ? I tried creating 3rd button that would to just that but inable to find a command that would remove the an empty line. Changed Source script attached.Desktop.rar Edited June 17, 2009 by lessstoopid Link to comment Share on other sites More sharing options...
microbious Posted June 19, 2009 Author Share Posted June 19, 2009 Ok fixed it Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now