Guten Morgen,
nach langer Zeit wollte ich mich wieder einmal der 'gebauten' MyArrayDisplay von Autobert bedienen
(seinerzeit hatte ich diese beim einem grossen Migrationsprojekt beim Anzeigen von AD Infos genutzt).
In dem jetzigen Anwendungsfall geht es um das rekursive Auslesen von Dateien inkl. der Dateigrößen.
Die Anzeige würde ich (wieder) mittels der MyArrayDisplay anpssen lassen. Leider klappt das nur noch bedingt, denn die Darstellung des Arrays
ist reduziert auf 2 schmale Spalten innerhalb der GUI - (Einen Screenshot habe ich als Datei attached)
Mir ist es bis dato nicht gelungen diesen Effekt zu fixen :-(((
Vielleicht weiss ja einer der 'Profis' weiter
Danke schon einmal im voraus.
Gruss UGT100
Rekursives Suchen
Code
#include<Array.au3>
#include<Date.au3>
#include<File.au3>
#include<MyArrayDisplay_new.au3>
Global $cdeDir = FileSelectFolder("Startverzeichnis für den DirScan auswählen:","")
SplashTextOn("Get Files and File Size", "Please wait - processing the requested filelist", 400, 50)
$cdeDir1 = StringReplace($cdeDir, ":", "_")
$cdeDir1 = StringReplace($cdeDir1, "\", "_")
$ret = _GetFilesFolder_Rekursiv($cdeDir, '*',0,0)
;~ If IsArray($ret) Then
;~ _ArrayDisplay($ret, 'Rekursiv alle Dateien')
;~ Else
;~ ConsoleWrite($ret & @CRLF)
;~ EndIf
Local $a2[Ubound($ret)][2] = [[$ret[0], '']]
For $i = 1 To $ret[0]
$a2[$i][0] = $ret[$i]
;~ $a2[$i][1] = (FileGetSize($ret[$i])) & " Bytes"
$a2[$i][1] = (FileGetSize($ret[$i]))
;~ $a2[$i][1] = Round(FileGetSize($ret[$i])/1048576) & " MB"
;~ $iSize = FileGetSize($ret[$i])
;~ If @error Then ConsoleWrite("Fehler bei Datei: " & $ret[$i] & @LF)
;~ $a2[$i][1] = Round($iSize) & " Bytes"
Next
$a = ''
_FileWriteFromArray(@ScriptDir & "\cdeFileSize_" & @ComputerName & "_" & $cdeDir1 & ".txt", $a2, 1)
_ArraySort($a2, 1, 0, 0, 1)
SplashOff()
;~ _ArrayDisplay($a2)
;~ MyArrayDisplay_new($a2, "Path: " & $cdeDir & ": Filelist Filesize", "500|300")
_MyArrayDisplay($a2, "Path: " & $cdeDir & ": Filelist Filesize", "500|300|500")
;==================================================================================================
; Function Name: _GetFilesFolder_Rekursiv($sPath [, $sExt='*' [, $iDir=-1 [, $iRetType=0 ,[$sDelim='0']]]])
; Description: Rekursive Auflistung von Dateien und/oder Ordnern
; Parameter(s): $sPath der Basispfad für die Auflistung ('.' -aktueller Pfad, '..' -Parentpfad)
; $sExt Erweiterung für Dateiauswahl '*' oder -1 für alle (Standard)
; $iDir -1 Dateien+Ordner(Standard), 0 nur Dateien, 1 nur Ordner
; optional: $iRetType 0 gibt Array, 1 gibt String zurück
; optional: $sDelim legt Trennzeichen für Stringrückgabe fest
; 0 -@CRLF (Standard) 1 -@CR 2 -@LF 3 -';' 4 -'|'
; Return Value(s): Array (Standard) od. String mit den gefundenen Pfaden der Dateien und/oder Ordner
; Array[0] enthält die Anzahl der gefundenen Dateien/Ordner
; Author(s): BugFix (bugfix@autoit.de)
;==================================================================================================
Func _GetFilesFolder_Rekursiv($sPath, $sExt='*', $iDir=-1, $iRetType=0, $sDelim='0')
Global $oFSO = ObjCreate('Scripting.FileSystemObject')
Global $strFiles = ''
Switch $sDelim
Case '1'
$sDelim = @CR
Case '2'
$sDelim = @LF
Case '3'
$sDelim = ';'
Case '4'
$sDelim = '|'
Case Else
$sDelim = @CRLF
EndSwitch
If ($iRetType < 0) Or ($iRetType > 1) Then $iRetType = 0
If $sExt = -1 Then $sExt = '*'
If ($iDir < -1) Or ($iDir > 1) Then $iDir = -1
_ShowSubFolders($oFSO.GetFolder($sPath),$sExt,$iDir,$sDelim)
If $iRetType = 0 Then
Local $aOut
$aOut = StringSplit(StringTrimRight($strFiles, StringLen($sDelim)), $sDelim, 1)
If $aOut[1] = '' Then
ReDim $aOut[1]
$aOut[0] = 0
EndIf
Return $aOut
Else
Return StringTrimRight($strFiles, StringLen($sDelim))
EndIf
EndFunc
Func _ShowSubFolders($Folder, $Ext='*', $Dir=-1, $Delim=@CRLF)
If Not IsDeclared("strFiles") Then Global $strFiles = ''
If ($Dir = -1) Or ($Dir = 0) Then
For $file In $Folder.Files
If $Ext <> '*' Then
If StringRight($file.Name, StringLen($Ext)) = $Ext Then _
$strFiles &= $file.Path & $Delim
Else
$strFiles &= $file.Path & $Delim
EndIf
Next
EndIf
For $Subfolder In $Folder.SubFolders
If ($Dir = -1) Or ($Dir = 1) Then $strFiles &= $Subfolder.Path & '\' & $Delim
_ShowSubFolders($Subfolder, $Ext, $Dir, $Delim)
Next
EndFunc
Alles anzeigen
und hier die eigentliche Func
C
#include-once
#include <array.au3>
#include <GuiListview.au3>
Func _MyArrayDisplay(Const ByRef $avArray, $sTitle = "Array: ListView Display", $sCols = 0, $iItemLimit = -1, $iTranspose = 0, $sSeparator = "", $sReplace = "|", $sHeader = "")
If Not IsArray($avArray) Then Return SetError(1, 0, 0)
$aCols = StringSplit($sCols, "|")
; Dimension checking
Local $iDimension = UBound($avArray, 0), $iUBound = UBound($avArray, 1) - 1, $iSubMax = UBound($avArray, 2) - 1
If $iDimension > 2 Then Return SetError(2, 0, 0)
; Separator handling
;~ If $sSeparator = "" Then $sSeparator = Chr(1)
If $sSeparator = "" Then $sSeparator = Chr(124)
; Check the separator to make sure it's not used literally in the array
If _ArraySearch($avArray, $sSeparator, 0, 0, 0, 1) <> -1 Then
For $x = 1 To 255
If $x >= 32 And $x <= 127 Then ContinueLoop
Local $sFind = _ArraySearch($avArray, Chr($x), 0, 0, 0, 1)
If $sFind = -1 Then
$sSeparator = Chr($x)
ExitLoop
EndIf
Next
EndIf
; Declare variables
Local $vTmp, $iBuffer = 64
Local $iColLimit = 250
Local $iOnEventMode = Opt("GUIOnEventMode", 0), $sDataSeparatorChar = Opt("GUIDataSeparatorChar", $sSeparator)
; Swap dimensions if transposing
If $iSubMax < 0 Then $iSubMax = 0
If $iTranspose Then
$vTmp = $iUBound
$iUBound = $iSubMax
$iSubMax = $vTmp
EndIf
; Set limits for dimensions
If $iSubMax > $iColLimit Then $iSubMax = $iColLimit
If $iItemLimit < 1 Then $iItemLimit = $iUBound
If $iUBound > $iItemLimit Then $iUBound = $iItemLimit
; Set header up
If $sHeader = "" Then
$sHeader = "Row " ; blanks added to adjust column size for big number of rows
For $i = 0 To $iSubMax
$sHeader &= $sSeparator & "Col " & $i
Next
EndIf
; Convert array into text for listview
Local $avArrayText[$iUBound + 1]
For $i = 0 To $iUBound
$avArrayText[$i] = "[" & $i & "]"
For $j = 0 To $iSubMax
; Get current item
If $iDimension = 1 Then
If $iTranspose Then
$vTmp = $avArray[$j]
Else
$vTmp = $avArray[$i]
EndIf
Else
If $iTranspose Then
$vTmp = $avArray[$j][$i]
Else
$vTmp = $avArray[$i][$j]
EndIf
EndIf
; Add to text array
$vTmp = StringReplace($vTmp, $sSeparator, $sReplace, 0, 1)
$avArrayText[$i] &= $sSeparator & $vTmp
; Set max buffer size
$vTmp = StringLen($vTmp)
If $vTmp > $iBuffer Then $iBuffer = $vTmp
Next
Next
$iBuffer += 1
; GUI Constants
Local Const $_ARRAYCONSTANT_GUI_DOCKBORDERS = 0x66
Local Const $_ARRAYCONSTANT_GUI_DOCKBOTTOM = 0x40
Local Const $_ARRAYCONSTANT_GUI_DOCKHEIGHT = 0x0200
Local Const $_ARRAYCONSTANT_GUI_DOCKLEFT = 0x2
Local Const $_ARRAYCONSTANT_GUI_DOCKRIGHT = 0x4
Local Const $_ARRAYCONSTANT_GUI_EVENT_CLOSE = -3
Local Const $_ARRAYCONSTANT_LVIF_PARAM = 0x4
Local Const $_ARRAYCONSTANT_LVIF_TEXT = 0x1
Local Const $_ARRAYCONSTANT_LVM_GETCOLUMNWIDTH = (0x1000 + 29)
Local Const $_ARRAYCONSTANT_LVM_GETITEMCOUNT = (0x1000 + 4)
Local Const $_ARRAYCONSTANT_LVM_GETITEMSTATE = (0x1000 + 44)
Local Const $_ARRAYCONSTANT_LVM_INSERTITEMW = (0x1000 + 77)
Local Const $_ARRAYCONSTANT_LVM_SETEXTENDEDLISTVIEWSTYLE = (0x1000 + 54)
Local Const $_ARRAYCONSTANT_LVM_SETITEMW = (0x1000 + 76)
Local Const $_ARRAYCONSTANT_LVS_EX_FULLROWSELECT = 0x20
Local Const $_ARRAYCONSTANT_LVS_EX_GRIDLINES = 0x1
Local Const $_ARRAYCONSTANT_LVS_SHOWSELALWAYS = 0x8
Local Const $_ARRAYCONSTANT_WS_EX_CLIENTEDGE = 0x0200
Local Const $_ARRAYCONSTANT_WS_MAXIMIZEBOX = 0x00010000
Local Const $_ARRAYCONSTANT_WS_MINIMIZEBOX = 0x00020000
Local Const $_ARRAYCONSTANT_WS_SIZEBOX = 0x00040000
Local Const $_ARRAYCONSTANT_tagLVITEM = "int Mask;int Item;int SubItem;int State;int StateMask;ptr Text;int TextMax;int Image;int Param;int Indent;int GroupID;int Columns;ptr pColumns"
Local $iAddMask = BitOR($_ARRAYCONSTANT_LVIF_TEXT, $_ARRAYCONSTANT_LVIF_PARAM)
Local $tBuffer = DllStructCreate("wchar Text[" & $iBuffer & "]"), $pBuffer = DllStructGetPtr($tBuffer)
Local $tItem = DllStructCreate($_ARRAYCONSTANT_tagLVITEM), $pItem = DllStructGetPtr($tItem)
DllStructSetData($tItem, "Param", 0)
DllStructSetData($tItem, "Text", $pBuffer)
DllStructSetData($tItem, "TextMax", $iBuffer)
; Set interface up
Local $iWidth = 64, $iHeight = 480
Local $hGUI = GUICreate($sTitle, $iWidth, $iHeight, Default, Default, BitOR($_ARRAYCONSTANT_WS_SIZEBOX, $_ARRAYCONSTANT_WS_MINIMIZEBOX, $_ARRAYCONSTANT_WS_MAXIMIZEBOX))
Local $aiGUISize = WinGetClientSize($hGUI)
Local $hListView = GUICtrlCreateListView($sHeader, 0, 0, $aiGUISize[0], $aiGUISize[1] - 26, $_ARRAYCONSTANT_LVS_SHOWSELALWAYS)
Local $hCopy = GUICtrlCreateButton("Copy Selected", 3, $aiGUISize[1] - 23, $aiGUISize[0] - 6, 20)
GUICtrlSetResizing($hListView, $_ARRAYCONSTANT_GUI_DOCKBORDERS)
GUICtrlSetResizing($hCopy, $_ARRAYCONSTANT_GUI_DOCKLEFT + $_ARRAYCONSTANT_GUI_DOCKRIGHT + $_ARRAYCONSTANT_GUI_DOCKBOTTOM + $_ARRAYCONSTANT_GUI_DOCKHEIGHT)
GUICtrlSendMsg($hListView, $_ARRAYCONSTANT_LVM_SETEXTENDEDLISTVIEWSTYLE, $_ARRAYCONSTANT_LVS_EX_GRIDLINES, $_ARRAYCONSTANT_LVS_EX_GRIDLINES)
GUICtrlSendMsg($hListView, $_ARRAYCONSTANT_LVM_SETEXTENDEDLISTVIEWSTYLE, $_ARRAYCONSTANT_LVS_EX_FULLROWSELECT, $_ARRAYCONSTANT_LVS_EX_FULLROWSELECT)
GUICtrlSendMsg($hListView, $_ARRAYCONSTANT_LVM_SETEXTENDEDLISTVIEWSTYLE, $_ARRAYCONSTANT_WS_EX_CLIENTEDGE, $_ARRAYCONSTANT_WS_EX_CLIENTEDGE)
; Fill listview
Local $aItem
For $i = 0 To $iUBound
If GUICtrlCreateListViewItem($avArrayText[$i], $hListView) = 0 Then
; use GUICtrlSendMsg() to overcome AutoIt limitation
$aItem = StringSplit($avArrayText[$i], $sSeparator)
DllStructSetData($tBuffer, "Text", $aItem[1])
; Add listview item
DllStructSetData($tItem, "Item", $i)
DllStructSetData($tItem, "SubItem", 0)
DllStructSetData($tItem, "Mask", $iAddMask)
GUICtrlSendMsg($hListView, $_ARRAYCONSTANT_LVM_INSERTITEMW, 0, $pItem)
; Set listview subitem text
DllStructSetData($tItem, "Mask", $_ARRAYCONSTANT_LVIF_TEXT)
For $j = 2 To $aItem[0]
DllStructSetData($tBuffer, "Text", $aItem[$j])
DllStructSetData($tItem, "SubItem", $j - 1)
GUICtrlSendMsg($hListView, $_ARRAYCONSTANT_LVM_SETITEMW, 0, $pItem)
Next
EndIf
Next
;************************************************************************************
$iWidth = _GUICtrlListView_GetColumnWidth($hListView,0)
$iColCount = _GUICtrlListView_GetColumnCount($hListView)
;ConsoleWrite($aCols)
For $i = 1 To $iColCount - 1
If IsArray($aCols) Then
_GUICtrlListView_SetColumnWidth($hListView, $i, Number($aCols[$i]))
;ConsoleWrite($i & ": " & $aCols[$i])
If $aCols[$i] = -1 Then
;ConsoleWrite(" AutoSize")
_GUICtrlListView_SetColumnWidth($hListView, $i, $LVSCW_AUTOSIZE)
EndIf
EndIf
$iWidth += _GUICtrlListView_GetColumnWidth($hListView,$i)
ConsoleWrite(@CRLF)
Next
;************************************************************************************
#cs
; adjust window width
$iWidth = 0
For $i = 0 To $iSubMax + 1
$iWidth += GUICtrlSendMsg($hListView, $_ARRAYCONSTANT_LVM_GETCOLUMNWIDTH, $i, 0)
Next
#ce
If $iWidth < 250 Then $iWidth = 230
$iWidth += 20
If $iWidth > @DesktopWidth Then $iWidth = @DesktopWidth - 100
WinMove($hGUI, "", (@DesktopWidth - $iWidth) / 2, Default, $iWidth)
; Show dialog
GUISetState(@SW_SHOW, $hGUI)
While 1
Switch GUIGetMsg()
Case $_ARRAYCONSTANT_GUI_EVENT_CLOSE
ExitLoop
Case $hCopy
Local $sClip = ""
; Get selected indices [ _GUICtrlListView_GetSelectedIndices($hListView, True) ]
Local $aiCurItems[1] = [0]
For $i = 0 To GUICtrlSendMsg($hListView, $_ARRAYCONSTANT_LVM_GETITEMCOUNT, 0, 0)
If GUICtrlSendMsg($hListView, $_ARRAYCONSTANT_LVM_GETITEMSTATE, $i, 0x2) Then
$aiCurItems[0] += 1
ReDim $aiCurItems[$aiCurItems[0] + 1]
$aiCurItems[$aiCurItems[0]] = $i
EndIf
Next
; Generate clipboard text
If Not $aiCurItems[0] Then
For $sItem In $avArrayText
$sClip &= $sItem & @CRLF
Next
Else
For $i = 1 To UBound($aiCurItems) - 1
$sClip &= $avArrayText[$aiCurItems[$i]] & @CRLF
Next
EndIf
ClipPut($sClip)
EndSwitch
WEnd
GUIDelete($hGUI)
Opt("GUIOnEventMode", $iOnEventMode)
Opt("GUIDataSeparatorChar", $sDataSeparatorChar)
Return 1
EndFunc ;==>_MyArrayDisplay
Alles anzeigen