Jump to content

Recommended Posts

Posted

Hello everybody,

I trying to modify a file based on items who are stored in a array.

The purpose is to delete all lines in the Test-Maps.ini file where the words in the test_list.ini are NOT present

but I am a littlebit stock at the moment, any ideas or help?

Many thanks in advanced.

Kindly Regards

Koen

---------------------------------------------

This is my code what I currently have:

#include <GuiConstants.au3>
#include <Array.au3>
#include <file.au3>

Dim $Array
 _FileReadToArray("C:\Users\Koen\Desktop\FL\test_list.ini",$Array)
 ;_ArrayDisplay($Array, "as read")
Global $success = False
$file_name = "C:\Users\Koen\Desktop\FL\Test-Maps.ini"
$line_text_input = $Array
$file_count_lines = _FileCountLines($file_name)
for $i = 0 to $file_count_lines
    $Lines_text_output = FileReadLine($file_name, $i)
    if StringInStr($Lines_text_output, $line_text_input) then
        _FileWriteToLine($file_name, $i, "", 1)
        $success = True
        ExitLoop
    EndIf
Next
if $success = True Then
    MsgBox(0, "Success", "Line has been deleted")
Else
    MsgBox(0, "Failure", "Line wasn't found")
EndIf
Posted

Have you not tried the Ini functions?

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

Hello Guinnes,

First of all thanks for replying, maybe some missing information:

The ini files are not real ini fomated ( they are coming from an other program)

here is an example of one of the two ini files:

[/color]
[color="#225985"]TEST ENABLED ON
E1 10
E2 10
E3 
E4 
E5 10
E6 
E70 
E72 
E73

So the Ini functions will not work here.

Best regards

Koen

Posted

Ah OK.

Have a look at this, should give you some idea of where to start.

#include <File.au3>

Local $aArray_1 = 0, $aArray_2 = 0
_FileReadToArray(@ScriptDir & 'Example.ini', $aArray_1) ; test_list.ini
_FileReadToArray(@ScriptDir & 'Example_2.ini', $aArray_2) ; Test-Maps.ini

For $i = 1 To $aArray_1[0]
    For $j = 1 To $aArray_2[0]
        If StringStripWS($aArray_1[$i], 8) = StringStripWS($aArray_2[$j], 8) Then
            ContinueLoop 2
        EndIf
    Next
    ConsoleWrite('Delete: ' & $aArray_1[$i] & @CRLF)
Next

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

Hi Guinness,

Many thanks that is almost what i need

however is there a way to remove/ ignore everything after the first white space (actually a TAB) ??

Thanks,

Koen

Posted

Look at the parameter of StringStripWS.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...