Steviep Posted November 1, 2016 Posted November 1, 2016 Hi all, I have a script which is used as part of a wrapper for an installer. The script is responsible to performing certain actions, a lot of which involve IniRead & IniWrite. Today I have been presented with a tricky situation, here's what I am trying to accomplish: The AutoIT script will read an existing .INI file which contains a section like this: [Customise] CustomScript = "Bemaßen" , "Störmer" , "Schließn" , "Schnell schließen" , "" , "OnCloseNoImage.rpt" , "Schnelles schließen der Planung ohne Ansichten zu erzeugen" , "" , "0" CustomScript = "Einfügen" , "Störmer" , "Schließn" , "Schnell schließen" , "" , "OnCloseNoImage.rpt" , "Schnelles schließen der Planung ohne Ansichten zu erzeugen" , "" , "0" CustomScript = "Ansicht" , "Störmer" , "Schließn" , "Schnell schließen" , "" , "OnCloseNoImage.rpt" , "Schnelles schließen der Planung ohne Ansichten zu erzeugen" , "" , "0" CustomScript = "Start" , "Insight" , "Planung ersetzen" , "Prüfen" , "" , "ValidateItems.rpt" , "Prüfen der Artikelkonfiguration" , "" , "0" CustomScript = "Start" , "Insight" , "Prüfen" , "Preis" , "" , "PriceItems.rpt" , "Preise bestimmen" , "" , "0" CustomScript = "Start" , "Insight" , "Preis" , "Abbrechen" , "" , "AbortChanges.rpt" , "Abbrechen der Planung ohne aktuelle Änderungen zu übernehmen" , "" , "0" CustomScript = "Start" , "Insight" , "Abbrechen" , "Spiegeln" , "" , "OnMirror.rpt" , "Horizontales oder vertikales Spiegeln der aktuellen Planung" , "" , "0" CustomScript = "Start" , "Insight" , "Spiegeln" , "Schnell schließen" , "" , "OnCloseNoImage.rpt" , "Schnelles schließen der Planung ohne Ansichten zu erzeugen" , "" , "0" CustomScript = "Start" , "Insight" , "Schnell schließen" , "Schließn" , "" , "OnClose.rpt" , "Schnelles schließen der Planung mit Ansichten zu erzeugen" , "" , "0" I need to delete only the lines which contain "CustomScript = "Start" , "Insight"". I have not had any luck with IniDelete since this function only accepts Filename, Section and Key, but no value. Any suggestions? Many thanks!
jchd Posted November 1, 2016 Posted November 1, 2016 This file structure is incompatible with .INI conventions: duplicate keys can't be handled properly using standard calls. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
Steviep Posted November 1, 2016 Author Posted November 1, 2016 Thanks for the quick response JCHD. I had a feeling this might be the case. As a workaround, do you believe there would be a way to simply delete any line which starts with "CustomScript = "Start" , "Insight"" ?
Moderators Melba23 Posted November 1, 2016 Moderators Posted November 1, 2016 Steviep, Read the file to an array and then check each line to see if it matches the required format - delete it if it does: #include <Array.au3> ; Simulate reading file to an array Global $aLines[] = ['[Customise]', _ 'CustomScript = "Bemaßen" , "Störmer" , "Schließn" , "Schnell schließen" , "" , "OnCloseNoImage.rpt" , "Schnelles schließen der Planung ohne Ansichten zu erzeugen" , "" , "0"', _ 'CustomScript = "Einfügen" , "Störmer" , "Schließn" , "Schnell schließen" , "" , "OnCloseNoImage.rpt" , "Schnelles schließen der Planung ohne Ansichten zu erzeugen" , "" , "0"', _ 'CustomScript = "Ansicht" , "Störmer" , "Schließn" , "Schnell schließen" , "" , "OnCloseNoImage.rpt" , "Schnelles schließen der Planung ohne Ansichten zu erzeugen" , "" , "0"', _ 'CustomScript = "Start" , "Insight" , "Planung ersetzen" , "Prüfen" , "" , "ValidateItems.rpt" , "Prüfen der Artikelkonfiguration" , "" , "0"', _ 'CustomScript = "Start" , "Insight" , "Prüfen" , "Preis" , "" , "PriceItems.rpt" , "Preise bestimmen" , "" , "0"', _ 'CustomScript = "Start" , "Insight" , "Preis" , "Abbrechen" , "" , "AbortChanges.rpt" , "Abbrechen der Planung ohne aktuelle Änderungen zu übernehmen" , "" , "0"', _ 'CustomScript = "Start" , "Insight" , "Abbrechen" , "Spiegeln" , "" , "OnMirror.rpt" , "Horizontales oder vertikales Spiegeln der aktuellen Planung" , "" , "0"', _ 'CustomScript = "Start" , "Insight" , "Spiegeln" , "Schnell schließen" , "" , "OnCloseNoImage.rpt" , "Schnelles schließen der Planung ohne Ansichten zu erzeugen" , "" , "0"', _ 'CustomScript = "Start" , "Insight" , "Schnell schließen" , "Schließn" , "" , "OnClose.rpt" , "Schnelles schließen der Planung mit Ansichten zu erzeugen" , "" , "0"'] $sString = 'CustomScript = "Start" , "Insight"' $iLen = StringLen($sString) ; Now examine each line - note we start at the end For $i = UBound($aLines) - 1 To 0 Step -1 ; If the line starts with the required text If StringLeft($aLines[$i], $iLen) = $sString Then ; Delete it _ArrayDelete($aLines, $i) EndIf Next ; And here is the result _ArrayDisplay($aLines, "", Default, 8) M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
jchd Posted November 1, 2016 Posted November 1, 2016 Normally I would be very tempted to add that a highly generic, flexible, safe and powerful file storage for application data is best achieved by SQLite, but of course I wouldn't dare to say that here Yet all these kind of issues (and much more) would be quickly elegantly solved by doing so. Worth $0.02. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
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