Robocopy Folder exclusion bilden

  • Hallo zusammen

    Ich will zwei Verzeichnisse vergleichen, und alle Unter-Verzeichnisse die nicht in beiden Verzeichnissen enthalten sind - in eine Exclusion-Liste schreiben.

    Robocopy benötigt die Exclusionliste in der Form: "Verzeichniss1" "Verzeichniss" "Verzeichniss3"

    [autoit]

    #include <array.au3>
    #include <File.au3>
    Opt("GUIDataSeparatorChar",'""') ; "|" ist der Standard
    $txt1=_FileListToArray("\\server1\\ntinst\Install\","*","2")
    $txt2=_FileListToArray("\\server2\ntinstT\Install\","*","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
    $completexclusions = $diff1 & $diff2

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

    ;MsgBox(0, '', 'Addiert: ' & $completexclusions)
    ; Dieser Teil will nicht
    ;
    ;

    [/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 [i][0]=Intersection
    ; [i][1]=Difference 1
    ; [i][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]


    Ich bin schon so verzeifelt, dass ich versucht habe, mit

    [autoit]


    $myFile = FileOpen(@ScriptDir & '\textfile.txt', 1)
    For $i = 1 To $completexclusions[0]
    FileWriteLine ($myFile, '"' & $completexclusions[$i] & '"')
    Next
    FileClose($myFile)

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

    ein File anzulegen, um dieses später wieder einzulesen. Zeilenumbrüche entfernen traue ich mir dann wieder zu :wacko:

    Auch versuche mit;

    [autoit]

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

    [/autoit]

    oder

    [autoit]

    Opt("GUIDataSeparatorChar",'""')

    [/autoit]

    Alles nur käse ;(

    Ich hoffe ihr wisst rat.

    Einmal editiert, zuletzt von Surfy (25. Juli 2011 um 08:46)

  • 1. Du kannst gleich alles in eine Variable schreiben anstatt 2 einzelne Strings welche du dann danach zusammenbastelst.
    2. Warum formatierst du den String so das als Trennzeichen ein ";" genommen wird wenn du doch die Einträge in Anführungszeichen haben willst und mit Leerzeichen getrennt?

    Möchtest du folgendes erreichen?:

    Spoiler anzeigen
    [autoit]

    #include <File.au3>

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

    Global $a_txt1 = _FileListToArray("\\server1\\ntinst\Install\","*","2")
    Global $a_txt2 = _FileListToArray("\\server2\\ntinst\Install\","*","2")
    Global $s_Diff = ""

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

    Global $a_Intersect = _GetIntersection($a_txt1, $a_txt2)
    If Not @error Then
    For $i = 0 To UBound($a_Intersect) - 1
    If $a_Intersect[$i][1] <> '' Then $s_Diff &= '"' & $a_Intersect[$i][1] & '" '
    If $a_Intersect[$i][2] <> '' Then $s_Diff &= '"' & $a_Intersect[$i][2] & '" '

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

    If $a_Intersect[$i][1] == "" And $a_Intersect[$i][2] = "" Then ExitLoop ; Bricht Schleife ab wenn nix mehr da ist
    Next
    EndIf

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

    ConsoleWrite($s_Diff & @CRLF)

    [/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 [i][0]=Intersection
    ; [i][1]=Difference 1
    ; [i][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]

    Einmal editiert, zuletzt von AspirinJunkie (25. Juli 2011 um 14:31)