Array bearbeiten / verwenden und die Trennzeichen

  • [autoit]

    #include <array.au3>
    #include <File.au3>

    [/autoit][autoit][/autoit][autoit]

    $txt1=_FileListToArray("c:\testdir1\","*","2")
    $txt2=_FileListToArray("c:\testdir2\","*","2")

    [/autoit][autoit][/autoit][autoit]

    $ret = _GetIntersection($txt1, $txt2, 0, ' ')
    $diff1 = ''
    $diff2 = ''
    If Not @error Then
    For $i = 0 To UBound($ret) -1
    If $ret[$i][1] <> '' Then $diff1 &= $ret[$i][1] & ' ; '
    If $ret[$i][2] <> '' Then $diff2 &= $ret[$i][2] & ' ; '
    Next
    EndIf
    MsgBox(0, '', 'Unterschiede 1: ' & $diff1 & @LF & 'Unterschiede 2: ' & $diff2)

    [/autoit]

    Das Ergebniss sieht so aus:

    .....Dir1; ....dir2 ; ....Dir Mytest ;

    Wie bekomme ich nun eine Liste in der Form:

    "....Dir1" "....Dir2" ".... Dir Mytest"

    Gar nicht so einfach, das ganze ;(

  • Danke für den Tip!

    Ich probiersmal mit dem Spoiler :love:

    Spoiler anzeigen
    [autoit]

    ]#include <array.au3>
    #include <File.au3>

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $txt1=_FileListToArray("c:\temp1\","*","2")
    $txt2=_FileListToArray("c:\temp2\","*","2")

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $ret = _GetIntersection($txt1, $txt2, 0, ' ')
    $diff1 = ''
    $diff2 = ''
    If Not @error Then
    For $i = 0 To UBound($ret) -1
    If $ret[$i][1] <> '' Then $diff1 &= $ret[$i][1] & ' ; '
    If $ret[$i][2] <> '' Then $diff2 &= $ret[$i][2] & ' ; '
    Next
    EndIf
    MsgBox(0, '', 'Unterschiede 1: ' & $diff1 & @LF & 'Unterschiede 2: ' & $diff2)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ;_ArrayToString($diff2, "|", 1, 7))

    [/autoit] [autoit][/autoit] [autoit]

    $array = StringSplit($diff2, ' ;', 1)
    _ArrayDisplay($array)
    $nimmerarray=_ArrayToString($Array, ' "', 1,50)

    [/autoit] [autoit][/autoit] [autoit]

    MsgBox(0, "_ArrayToString() erhält von $avArray die Items 1 bis 7", _ArrayToString($Array, '"', 1,50))

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $sIni = @ScriptDir & "\debug.ini"
    $counter = IniRead($sIni, @ComputerName, "Counter", "")
    $recount=$counter + 1
    $sData = "Username=" & @UserName & @LF & "Computername=" & @ComputerName & @LF & "Uhrzeit=" & @HOUR & ":" & @MIN & @LF & "Datum=" & @MDAY & "." & @MON & "." & @YEAR & @LF & "Counter=" & $recount & @LF & "Diff1="& $diff1 & @LF & "Diff2=" & $diff2& @LF & "Bearbeitet=" & $nimmerarray
    IniWriteSection($sIni, @ComputerName, $sData)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ;==================================================================================================
    ; Function Name: _GetIntersection($Set1, $Set2 [, $GetAll=0 [, $Delim=Default]])
    ; Description:: Detect from 2 sets
    ; - Intersection (elements are contains in both sets)
    ; - Difference 1 (elements are contains only in $Set1)
    ; - Difference 2 (elements are contains only in $Set2)
    ; Parameter(s): $Set1 set 1 (1D-array or delimited string)
    ; $Set2 set 2 (1D-array or delimited string)
    ; optional: $GetAll 0 - only one occurence of every different element are shown (Default)
    ; 1 - all elements of differences are shown
    ; optional: $Delim Delimiter for strings (Default use the separator character set by Opt("GUIDataSeparatorChar") )
    ; Return Value(s): Succes 2D-array [0]=Intersection
    ; [1]=Difference 1
    ; [2]=Difference 2
    ; Failure -1 @error set, that was given as array, is'nt 1D-array
    ; Note: Comparison is case-sensitiv! - i.e. Number 9 is different to string '9'!
    ; Author(s): BugFix ([email='bugfix@autoit.de'][/email])
    ;==================================================================================================
    Func _GetIntersection(ByRef $Set1, ByRef $Set2, $GetAll=0, $Delim=Default)
    Local $o1 = ObjCreate("System.Collections.ArrayList")
    Local $o2 = ObjCreate("System.Collections.ArrayList")
    Local $oUnion = ObjCreate("System.Collections.ArrayList")
    Local $oDiff1 = ObjCreate("System.Collections.ArrayList")
    Local $oDiff2 = ObjCreate("System.Collections.ArrayList")
    Local $tmp, $i
    If $GetAll <> 1 Then $GetAll = 0
    If $Delim = Default Then $Delim = Opt("GUIDataSeparatorChar")
    If Not IsArray($Set1) Then
    If Not StringInStr($Set1, $Delim) Then
    $o1.Add($Set1)
    Else
    $tmp = StringSplit($Set1, $Delim)
    For $i = 1 To UBound($tmp) -1
    $o1.Add($tmp[$i])
    Next
    EndIf
    Else
    If UBound($Set1, 0) > 1 Then Return SetError(1,0,-1)
    For $i = 0 To UBound($Set1) -1
    $o1.Add($Set1[$i])
    Next
    EndIf
    If Not IsArray($Set2) Then
    If Not StringInStr($Set2, $Delim) Then
    $o2.Add($Set2)
    Else
    $tmp = StringSplit($Set2, $Delim)
    For $i = 1 To UBound($tmp) -1
    $o2.Add($tmp[$i])
    Next
    EndIf
    Else
    If UBound($Set2, 0) > 1 Then Return SetError(1,0,-1)
    For $i = 0 To UBound($Set2) -1
    $o2.Add($Set2[$i])
    Next
    EndIf
    For $tmp In $o1
    If $o2.Contains($tmp) And Not $oUnion.Contains($tmp) Then $oUnion.Add($tmp)
    Next
    For $tmp In $o2
    If $o1.Contains($tmp) And Not $oUnion.Contains($tmp) Then $oUnion.Add($tmp)
    Next
    For $tmp In $o1
    If $GetAll Then
    If Not $oUnion.Contains($tmp) Then $oDiff1.Add($tmp)
    Else
    If Not $oUnion.Contains($tmp) And Not $oDiff1.Contains($tmp) Then $oDiff1.Add($tmp)
    EndIf
    Next
    For $tmp In $o2
    If $GetAll Then
    If Not $oUnion.Contains($tmp) Then $oDiff2.Add($tmp)
    Else
    If Not $oUnion.Contains($tmp) And Not $oDiff2.Contains($tmp) Then $oDiff2.Add($tmp)
    EndIf
    Next
    Local $UBound[3] = [$oDiff1.Count,$oDiff2.Count,$oUnion.Count], $max = 1
    For $i = 0 To UBound($UBound) -1
    If $UBound[$i] > $max Then $max = $UBound[$i]
    Next
    Local $aOut[$max][3]
    If $oUnion.Count > 0 Then
    $i = 0
    For $tmp In $oUnion
    $aOut[$i][0] = $tmp
    $i += 1
    Next
    EndIf
    If $oDiff1.Count > 0 Then
    $i = 0
    For $tmp In $oDiff1
    $aOut[$i][1] = $tmp
    $i += 1
    Next
    EndIf
    If $oDiff2.Count > 0 Then
    $i = 0
    For $tmp In $oDiff2
    $aOut[$i][2] = $tmp
    $i += 1
    Next
    EndIf
    Return $aOut
    EndFunc ;==>_GetIntersection

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit]


    Die Messagebox Ergebnisse sehen nun schon vielversprechend aus, aber so ein richtiger String scheint es noch nicht zu sein, den im Logfile landet nur ein leerer Eintrag.


    Das ganze scheint auch nur ein Gänsefüsschen zu setzten, für das Strichkomma welches ich als Trennzeichen ersetze. Wie ich auch an den Anfang ein Strichkomma bekomme, ist mir noch schleierhaft.


    Vielleicht habt ihr mir auch dazu eine Hilfestellung ;)




    Surfy

  • Das scheint logisch: ;)

    $ret = _GetIntersection($txt1, $txt2, 0, '"')

    Allerdings scheine ich da auch auch noch ein Problemchen zu haben, die Gänsefüssen entstehen nicht wie gewünscht :(