This script:
;https://autoit.de/index.php?thread/86082-treeview-root-verbergen/&postID=691139#post691139
#include <File.au3>
#include <WindowsConstants.au3>
Global $sPath = @ScriptDir
Global $hGui = GUICreate('TreeView-Example', 400, 600)
Global $idTreeView = GUICtrlCreateTreeView(10, 10, 380, 580, Default, $WS_EX_CLIENTEDGE)
GUISetState()
_CreatePath($sPath, $idTreeView)
Do
Until GUIGetMsg() = -3
Func _CreatePath($sPath, $idParent)
Local $aFolder, $aFiles, $idItem
If StringRight($sPath, 1) <> '\' Then $sPath &= '\'
$aFolder = _FileListToArray($sPath, '*', $FLTA_FOLDERS)
If Not @error Then
For $i = 1 To $aFolder[0]
$idItem = GUICtrlCreateTreeViewItem($aFolder[$i], $idParent)
_CreatePath($sPath & $aFolder[$i], $idItem)
Next
EndIf
$aFiles = _FileListToArray($sPath, '*', $FLTA_FILES)
If @error Then Return
For $i = 1 To $aFiles[0]
$idItem = GUICtrlCreateTreeViewItem($aFiles[$i], $idParent)
Next
EndFunc
does same as yours with native GUICtrlCreateTreeViewItem and _FileListToArray.