Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;;;;;;;;;;;;;;;;;;;;;; Gör detta fast gör en FileListToaArrayRec som SORTERAR SKITEN FÖRST sedan simulerar DETTA
- #include <GuiTreeView.au3>
- #include <WINapiSHELLEX.au3>
- #include <array.au3>
- #include <file.au3>
- Global Const $TVSORTCB = "ptr Parent;ptr Compare;lparam SortParam;"
- Global Enum $OPT_1, $OPT_2
- $hGui = GUICreate("Demo1", 600, 400)
- Local $hTreeView = _GUICtrlTreeView_Create($hGui, 10, 10, 580, 380)
- GUISetState()
- Local $test = _GuictrlTreeview__FileListToArrayRec($hTreeView, "C:\Users\tis\Desktop\Autoit\DeDu Masterpiece", ".au3", "BackUp;.git*;___TrashCan")
- _ArrayDisplay($test);
- ;_ArraySort($test)
- ;_ArrayDisplay($test);
- Do
- Until GUIGetMsg() = -3
- Func _GuictrlTreeview__FileListToArrayRec($hTreeView, $sPath, $iExtFilters = "*.*", $iExclFilters = "")
- Local $hItems[1] = [0]
- ; Filter files
- Local $matchExtensions = StringSplit($iExtFilters, ";")
- Local $matchFolders = StringSplit($iExclFilters, ";")
- ; Set default icons (late rreplaced with file associated icon
- Local $hImageList = _GUIImageList_Create(16, 16, 5, 1)
- _GUICtrlTreeView_SetNormalImageList($hTreeView, $hImageList)
- ;$matchExtensions, $matchFolders
- _GUICtrlTreeView_BeginUpdate($hTreeView)
- _ListFiles_ToTreeView($hItems, $hTreeView, $sPath, 0, $hImageList, $matchExtensions, $matchFolders)
- _GUICtrlTreeView_EndUpdate($hTreeView)
- Return $hItems
- EndFunc ;==>_GuictrlTreeview__FileListToArrayRec
- Func _ListFiles_ToTreeView(ByRef $hItems, $hTreeView, $sSourceFolder, $hItem, $hImageList, $matchExtensions, $matchFolders)
- Local $sFile, $hIcon, $hIcon_Index, $sCurFullFilePath, $hChild, $IgnoreFolder, $DenyFile
- ; Force a trailing \
- If StringRight($sSourceFolder, 1) <> "\" Then $sSourceFolder &= "\"
- ; Start the search
- Local $hSearch = FileFindFirstFile($sSourceFolder & "*.*")
- ; If no files found then return
- If $hSearch = -1 Then Return ; This is where we break the recursive loop <<<<<<<<<<<<<<<<<<<<<<<<<<
- ; Now run through the contents of the folder
- While 1
- ; $IgnoreFile
- $IgnoreFolder = False
- $DenyFile = False
- ; Get next match
- $sFile = FileFindNextFile($hSearch)
- ; If no more files then close search handle and return
- If @error Then ExitLoop ; This is where we break the recursive loop <<<<<<<<<<<<<<<<<<<<<<<<<<
- ; Ignore these folders
- For $i = 1 To $matchFolders[0]
- If $sFile == $matchFolders[$i] Then $IgnoreFolder = True
- Next
- If $IgnoreFolder Then ContinueLoop
- ; Check if a folder
- If @extended Then
- ; If so then call the function recursively
- $sCurFullFilePath = $sSourceFolder & $sFile
- ; Get da icon
- $hIcon = _WinAPI_ShellExtractAssociatedIcon($sSourceFolder & $sFile, 1)
- $hIcon_Index = _GUIImageList_ReplaceIcon($hImageList, -1, $hIcon)
- $hChild = _GUICtrlTreeView_AddChild($hTreeView, $hItem, $sFile, $hIcon_Index, $hIcon_Index)
- _WinAPI_DestroyIcon($hIcon)
- _Array_Push($hItems, $sCurFullFilePath)
- _ListFiles_ToTreeView($hItems, $hTreeView, $sCurFullFilePath, $hChild, $hImageList, $matchExtensions, $matchFolders)
- Else
- $sCurFullFilePath = $sSourceFolder & $sFile
- ; accept only files
- For $i = 1 To $matchExtensions[0]
- If StringInStr($sFile, $matchExtensions[$i]) Then
- ; Get da icon
- $hIcon = _WinAPI_ShellExtractAssociatedIcon($sCurFullFilePath, 1)
- $hIcon_Index = _GUIImageList_ReplaceIcon($hImageList, -1, $hIcon)
- _WinAPI_DestroyIcon($hIcon)
- ; If a file than write path and name
- _GUICtrlTreeView_AddChild($hTreeView, $hItem, $sFile, $hIcon_Index, $hIcon_Index)
- _Array_Push($hItems, $sCurFullFilePath)
- EndIf
- Next
- If $matchExtensions[1] == "" Then
- ; Get da icon
- $hIcon = _WinAPI_ShellExtractAssociatedIcon($sCurFullFilePath, 1)
- $hIcon_Index = _GUIImageList_ReplaceIcon($hImageList, -1, $hIcon)
- _WinAPI_DestroyIcon($hIcon)
- ; If a file than write path and name
- _GUICtrlTreeView_AddChild($hTreeView, $hItem, $sFile, $hIcon_Index, $hIcon_Index)
- _Array_Push($hItems, $sCurFullFilePath)
- EndIf
- EndIf
- WEnd
- ; Close search handle
- FileClose($hSearch)
- EndFunc ;==>_ListFiles_ToTreeView
- Func _Array_Push(ByRef $a, $v)
- If Not IsArray($a) Then
- ConsoleWrite("! _Array_Push used with non array" & @CRLF)
- Return False
- EndIf
- ReDim $a[$a[0] + 2]
- $a[$a[0] + 1] = $v
- $a[0] += 1
- Return $a[0]
- EndFunc ;==>_Array_Push
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement