Hi,
Spoiler anzeigen
AutoIt
Opt("GUIOnEventMode", 1)
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
Global $g_sPath_Ini = @scriptdir & "\Settings.ini"
Global $g_sPath_Source = IniRead($g_sPath_Ini, "Path", "Source", "E:\Daten")
Global $g_sPath_Dest = IniRead($g_sPath_Ini, "Path", "Dest", "F:\Dokumente\Aussendienst")
Global $g_aLV_Folder[0][2]
Global $g_hGUI = GUICreate("Projekt Kopieren", 500, 500, -1, -1, $WS_SIZEBOX)
Opt("GUIResizeMode", BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKSIZE))
GUICtrlCreateLabel("Quellordner:", 0, 23, 70, 19, $SS_RIGHT)
Global $g_idInput_Path_Source = GUICtrlCreateInput($g_sPath_Source, 80, 20, 350, 20)
GUICtrlSetResizing($g_idInput_Path_Source, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKHEIGHT, $GUI_DOCKRIGHT))
GUICtrlSetState($g_idInput_Path_Source, $GUI_DISABLE)
Global $g_idButton_Path_Source = GUICtrlCreateButton("...", 435, 20, 30, 20)
GUICtrlSetResizing($g_idButton_Path_Source, BitOR($GUI_DOCKTOP, $GUI_DOCKRIGHT, $GUI_DOCKSIZE))
GUICtrlCreateLabel("Zielordner:", 0, 53, 70, 19, $SS_RIGHT)
Global $g_idInput_Path_Dest = GUICtrlCreateInput($g_sPath_Dest, 80, 50, 350, 20)
GUICtrlSetResizing($g_idInput_Path_Dest, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKHEIGHT, $GUI_DOCKRIGHT))
GUICtrlSetState($g_idInput_Path_Dest, $GUI_DISABLE)
Global $g_idButton_Path_Dest = GUICtrlCreateButton("...", 435, 50, 30, 20)
GUICtrlSetResizing($g_idButton_Path_Dest, BitOR($GUI_DOCKTOP, $GUI_DOCKRIGHT, $GUI_DOCKSIZE))
Opt("GUIResizeMode", $GUI_DOCKBORDERS)
Global $g_idLV_SelectFolder = GUICtrlCreateListView("Projekt", 5, 100, 490, 340, $LVS_LIST, $LVS_EX_CHECKBOXES)
Opt("GUIResizeMode", BitOR($GUI_DOCKRIGHT, $GUI_DOCKBOTTOM, $GUI_DOCKSIZE))
Global $g_idButton_ResetColor = GUICtrlCreateButton("Färbung entf.", 10, 450, 90, 22)
Global $g_idButton_SelectInv = GUICtrlCreateButton("Auswahl umkehren", 110, 450, 110, 22)
Global $g_idButton_Save = GUICtrlCreateButton("Pfade Speichern", 230, 450, 150, 22)
GUICtrlSetState($g_idButton_Save, $GUI_DISABLE)
Global $g_idButton_Start = GUICtrlCreateButton("Kopieren", 390, 450, 100, 22)
GUICtrlSetOnEvent($g_idButton_Path_Source, "Event_Button_Source")
GUICtrlSetOnEvent($g_idButton_Path_Dest, "Event_Button_Dest")
GUICtrlSetOnEvent($g_idButton_ResetColor, "Event_Button_ResetColor")
GUICtrlSetOnEvent($g_idButton_SelectInv, "Event_Button_SelectInv")
GUICtrlSetOnEvent($g_idButton_Save, "Event_Button_Save")
GUICtrlSetOnEvent($g_idButton_Start, "Event_Button_Start")
GUISetOnEvent($GUI_EVENT_CLOSE, "Event_Close")
LoadFolderInListView($g_sPath_Source)
GUISetState(1,$g_hGUI)
CheckFolder()
While 1
sleep(1000)
WEnd
Func CopyProject($aFolder, $sPathSource, $sPathTarget); Übernimmt die eigentliche Kopierarbeit
Local $sFolderSource, $sFolderTarget, $sFilesFail = ""
For $i = 0 to UBound($aFolder) -1
GUICtrlSetColor($aFolder[$i][1], 0x0000FF)
$sFolderSource = $sPathSource & "\" & $aFolder[$i][0] & "\Dokument-Explorer\Berechnungen"
$sFolderTarget = $sPathTarget & "\" & StringLeft($aFolder[$i][0], 4) & "\" & StringTrimLeft($aFolder[$i][0], 2) & "\Berechnungen"
ConsoleWrite($sFolderSource & " --> COPY --> " & $sFolderTarget & @crlf)
DirCreate($sFolderTarget)
If DirCopy($sFolderSource, $sFolderTarget, $FC_OVERWRITE) Then
GUICtrlSetColor($aFolder[$i][1], 0x00FF00)
GUICtrlSetState($aFolder[$i][1], $GUI_UNCHECKED)
Else
$sFilesFail &= $sFolderSource & @crlf & @crlf
GUICtrlSetColor($aFolder[$i][1], 0xFF0000)
EndIf
Next
If $sFilesFail <> "" Then MsgBox(16, "Fehler", "Folge Dateien konnten nicht kopiert werden: " & @crlf & @crlf & $sFilesFail)
EndFunc
Func CheckFolder(); Überprüft ob die Ordner ereichbar sind
Local $bReady = True
If Not FileExists($g_sPath_Source) Then
$bReady = False
MsgBox(16,"Fehler", "Quell-Ordner konnte nicht gefunden werden!")
EndIf
If Not FileExists($g_sPath_Dest) Then
$bReady = False
MsgBox(16,"Fehler", "Ziel-Ordner konnte nicht gefunden werden!")
EndIf
Return $bReady
EndFunc
Func Event_Button_Dest(); Auswählen des Zielordners über den Benützer
Local $sNewPath = FileSelectFolder("Bitte den Projekt-Ordner wählen", $g_sPath_Dest)
If @error Then Return
$g_sPath_Dest = $sNewPath
GUICtrlSetData($g_idInput_Path_Dest, $sNewPath)
GUICtrlSetState($g_idButton_Save, $GUI_ENABLE)
EndFunc
Func Event_Button_ResetColor(); Setzt die Einfärbug zurück
GUICtrlSetState($g_idLV_SelectFolder, $GUI_HIDE)
For $i = 0 to UBound($g_aLV_Folder) -1
GUICtrlSetColor($g_aLV_Folder[$i][1], 0x000000)
Next
GUICtrlSetState($g_idLV_SelectFolder, $GUI_SHOW)
EndFunc
Func Event_Button_Save(); Speichert die Pfade in einer Inidatei
Local $iWrite = 0
$iWrite += IniWrite($g_sPath_Ini, "Path", "Source", $g_sPath_Source)
$iWrite += IniWrite($g_sPath_Ini, "Path", "Dest", $g_sPath_Dest)
If $iWrite < 2 Then
MsgBox(16, "Error", "Speichern in Ini-Datei nicht möglich!")
Return
EndIf
GUICtrlSetState($g_idButton_Save, $GUI_DISABLE)
EndFunc
Func Event_Button_SelectInv(); Invertiert die Auswahl des ListView
Local $iState
GUICtrlSetState($g_idLV_SelectFolder, $GUI_HIDE)
For $i = 0 to UBound($g_aLV_Folder) -1
$iState = GUICtrlRead($g_aLV_Folder[$i][1], 1)
If BitAND($iState, $GUI_CHECKED) Then
GUICtrlSetState($g_aLV_Folder[$i][1], $GUI_UNCHECKED)
Else
GUICtrlSetState($g_aLV_Folder[$i][1], $GUI_CHECKED)
EndIf
Next
GUICtrlSetState($g_idLV_SelectFolder, $GUI_SHOW)
EndFunc
Func Event_Button_Start(); Listet die ausgewählten Projekte auf und ruft CopyProject() auf
If Not CheckFolder() Then Return
GUICtrlSetState($g_idButton_Start, $GUI_DISABLE)
GUICtrlSetData($g_idButton_Start, "Arbeitet")
Local $aFolderList[UBound($g_aLV_Folder)][2]
Local $iCounter = 0
For $i = 0 to UBound($g_aLV_Folder) -1
If BitAND(GUICtrlRead($g_aLV_Folder[$i][1], 1), $GUI_CHECKED) Then
$aFolderList[$iCounter][0] = $g_aLV_Folder[$i][0]
$aFolderList[$iCounter][1] = $g_aLV_Folder[$i][1]
$iCounter += 1
EndIf
Next
ReDim $aFolderList[$iCounter][2]
CopyProject($aFolderList, $g_sPath_Source, $g_sPath_Dest)
GUICtrlSetState($g_idButton_Start, $GUI_ENABLE)
GUICtrlSetData($g_idButton_Start, "Kopieren")
EndFunc
Func Event_Button_Source(); Auswählen des Quellordners über den Benützer
Local $sNewPath = FileSelectFolder("Bitte den Projekt-Ordner wählen", $g_sPath_Source)
If @error Then Return
$g_sPath_Source = $sNewPath
GUICtrlSetData($g_idInput_Path_Source, $sNewPath)
LoadFolderInListView($g_sPath_Source)
GUICtrlSetState($g_idButton_Save, $GUI_ENABLE)
EndFunc
Func Event_Close()
Exit
EndFunc
Func LoadFolderInListView($sPath); Listet die Projekte aus dem Quellordner auf, wenn sie dem Schema entsprechenden.
For $i = 0 to UBound($g_aLV_Folder) -1
$g_aLV_Folder[$i][0] = ""
GUICtrlDelete($g_aLV_Folder[$i][1])
Next
Local $aFolder = _FileListToArray($sPath, "*", $FLTA_FOLDERS, False)
If Not IsArray($aFolder) Then
ReDim $g_aLV_Folder[0][2]
Return
EndIf
Local $iCounter = 0
ReDim $g_aLV_Folder[ $aFolder[0] ][2]
For $i = 1 to $aFolder[0]
If StringRegExp($aFolder[$i], "\d\d\d\d....") Then
$g_aLV_Folder[$iCounter][0] = $aFolder[$i]
$g_aLV_Folder[$iCounter][1] = GUICtrlCreateListViewItem($aFolder[$i], $g_idLV_SelectFolder)
$iCounter += 1
EndIf
Next
ReDim $g_aLV_Folder[ $iCounter ][2]
EndFunc
Alles anzeigen
Die Inputboxen sind nun nicht mehr Zentriert sondern an den Kanten ausgerichtet, zuvor war das Resizing echt unglücklich.
Fertig Kopierte Elemente werden Grün gefärbt.
Es wird nun überprüft ob Ziel/Quell Ordner existieren.
mfg
Zeitriss