Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 4.35 KB | None | 0 0
  1. ;;;;;;;;;;;;;;;;;;;;;;; Gör detta fast gör en FileListToaArrayRec som SORTERAR SKITEN FÖRST sedan simulerar DETTA
  2. #include <GuiTreeView.au3>
  3. #include <WINapiSHELLEX.au3>
  4. #include <array.au3>
  5. #include <file.au3>
  6.  
  7. Global Const $TVSORTCB = "ptr Parent;ptr Compare;lparam SortParam;"
  8. Global Enum $OPT_1, $OPT_2
  9.  
  10.  
  11. $hGui = GUICreate("Demo1", 600, 400)
  12. Local $hTreeView = _GUICtrlTreeView_Create($hGui, 10, 10, 580, 380)
  13. GUISetState()
  14.  
  15.  
  16.  
  17. Local $test = _GuictrlTreeview__FileListToArrayRec($hTreeView, "C:\Users\tis\Desktop\Autoit\DeDu Masterpiece", ".au3", "BackUp;.git*;___TrashCan")
  18. _ArrayDisplay($test);
  19.  
  20. ;_ArraySort($test)
  21. ;_ArrayDisplay($test);
  22.  
  23.  
  24. Do
  25. Until GUIGetMsg() = -3
  26.  
  27. Func _GuictrlTreeview__FileListToArrayRec($hTreeView, $sPath, $iExtFilters = "*.*", $iExclFilters = "")
  28.     Local $hItems[1] = [0]
  29.     ; Filter files
  30.     Local $matchExtensions = StringSplit($iExtFilters, ";")
  31.     Local $matchFolders = StringSplit($iExclFilters, ";")
  32.  
  33.     ; Set default icons (late rreplaced with file associated icon
  34.     Local $hImageList = _GUIImageList_Create(16, 16, 5, 1)
  35.     _GUICtrlTreeView_SetNormalImageList($hTreeView, $hImageList)
  36.     ;$matchExtensions, $matchFolders
  37.  
  38.     _GUICtrlTreeView_BeginUpdate($hTreeView)
  39.     _ListFiles_ToTreeView($hItems, $hTreeView, $sPath, 0, $hImageList, $matchExtensions, $matchFolders)
  40.     _GUICtrlTreeView_EndUpdate($hTreeView)
  41.  
  42.     Return $hItems
  43. EndFunc   ;==>_GuictrlTreeview__FileListToArrayRec
  44.  
  45.  
  46.  
  47. Func _ListFiles_ToTreeView(ByRef $hItems, $hTreeView, $sSourceFolder, $hItem, $hImageList, $matchExtensions, $matchFolders)
  48.     Local $sFile, $hIcon, $hIcon_Index, $sCurFullFilePath, $hChild, $IgnoreFolder, $DenyFile
  49.  
  50.     ; Force a trailing \
  51.     If StringRight($sSourceFolder, 1) <> "\" Then $sSourceFolder &= "\"
  52.  
  53.     ; Start the search
  54.     Local $hSearch = FileFindFirstFile($sSourceFolder & "*.*")
  55.     ; If no files found then return
  56.     If $hSearch = -1 Then Return ; This is where we break the recursive loop <<<<<<<<<<<<<<<<<<<<<<<<<<
  57.  
  58.     ; Now run through the contents of the folder
  59.     While 1
  60.         ; $IgnoreFile
  61.         $IgnoreFolder = False
  62.         $DenyFile = False
  63.  
  64.         ; Get next match
  65.         $sFile = FileFindNextFile($hSearch)
  66.         ; If no more files then close search handle and return
  67.         If @error Then ExitLoop ; This is where we break the recursive loop <<<<<<<<<<<<<<<<<<<<<<<<<<
  68.  
  69.         ; Ignore these folders
  70.         For $i = 1 To $matchFolders[0]
  71.             If $sFile == $matchFolders[$i] Then $IgnoreFolder = True
  72.         Next
  73.  
  74.         If $IgnoreFolder Then ContinueLoop
  75.  
  76.         ; Check if a folder
  77.         If @extended Then
  78.  
  79.             ; If so then call the function recursively
  80.             $sCurFullFilePath = $sSourceFolder & $sFile
  81.  
  82.             ; Get da icon
  83.             $hIcon = _WinAPI_ShellExtractAssociatedIcon($sSourceFolder & $sFile, 1)
  84.             $hIcon_Index = _GUIImageList_ReplaceIcon($hImageList, -1, $hIcon)
  85.             $hChild = _GUICtrlTreeView_AddChild($hTreeView, $hItem, $sFile, $hIcon_Index, $hIcon_Index)
  86.             _WinAPI_DestroyIcon($hIcon)
  87.             _Array_Push($hItems, $sCurFullFilePath)
  88.  
  89.             _ListFiles_ToTreeView($hItems, $hTreeView, $sCurFullFilePath, $hChild, $hImageList, $matchExtensions, $matchFolders)
  90.         Else
  91.             $sCurFullFilePath = $sSourceFolder & $sFile
  92.  
  93.             ; accept only files
  94.             For $i = 1 To $matchExtensions[0]
  95.                 If StringInStr($sFile, $matchExtensions[$i]) Then
  96.                     ; Get da icon
  97.                     $hIcon = _WinAPI_ShellExtractAssociatedIcon($sCurFullFilePath, 1)
  98.                     $hIcon_Index = _GUIImageList_ReplaceIcon($hImageList, -1, $hIcon)
  99.                     _WinAPI_DestroyIcon($hIcon)
  100.  
  101.                     ; If a file than write path and name
  102.                     _GUICtrlTreeView_AddChild($hTreeView, $hItem, $sFile, $hIcon_Index, $hIcon_Index)
  103.  
  104.                     _Array_Push($hItems, $sCurFullFilePath)
  105.                 EndIf
  106.             Next
  107.             If $matchExtensions[1] == "" Then
  108.                 ; Get da icon
  109.                 $hIcon = _WinAPI_ShellExtractAssociatedIcon($sCurFullFilePath, 1)
  110.                 $hIcon_Index = _GUIImageList_ReplaceIcon($hImageList, -1, $hIcon)
  111.                 _WinAPI_DestroyIcon($hIcon)
  112.  
  113.                 ; If a file than write path and name
  114.                 _GUICtrlTreeView_AddChild($hTreeView, $hItem, $sFile, $hIcon_Index, $hIcon_Index)
  115.  
  116.                 _Array_Push($hItems, $sCurFullFilePath)
  117.  
  118.             EndIf
  119.  
  120.  
  121.  
  122.         EndIf
  123.     WEnd
  124.  
  125.     ; Close search handle
  126.     FileClose($hSearch)
  127.  
  128. EndFunc   ;==>_ListFiles_ToTreeView
  129.  
  130.  
  131. Func _Array_Push(ByRef $a, $v)
  132.     If Not IsArray($a) Then
  133.         ConsoleWrite("! _Array_Push used with non array" & @CRLF)
  134.         Return False
  135.     EndIf
  136.  
  137.     ReDim $a[$a[0] + 2]
  138.     $a[$a[0] + 1] = $v
  139.     $a[0] += 1
  140.     Return $a[0]
  141. EndFunc   ;==>_Array_Push
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement