Jump to content

Filling a TreeView with folders and files


Recommended Posts

Hello forum, i am tryning to fill a treeview with folders and files, i am using a recursive method taken from Here i am editing and editing but i can`t figure out how to make it work properly... the problem is that i don`t know how to put every item where should be.

Maybe someone else has look this before in the forum, i guess that is a common usage for a treeview, i`ve searched but i don`t find anything.

I attach a RAR with a couple of folders and TXT files for test propouses and my attempt script.

TREEVIEW.rar

Edited by monoscout999
Link to comment
Share on other sites

hi,

The solution is simpler than you may have thought. Using the same example from the wiki by Melba23, :mellow:

#include <GuiTreeView.au3>

$hGui = GUICreate("Demo1", 600, 400)
$hTreeView = _GUICtrlTreeView_Create($hGui, 10, 10, 580, 380)
GUISetState()

_GUICtrlTreeView_BeginUpdate($hTreeView)
ListFiles_ToTreeView(@ScriptDir, 0)
_GUICtrlTreeView_EndUpdate($hTreeView)

Do
Until GUIGetMsg() = -3

Func ListFiles_ToTreeView($sSourceFolder, $hItem)

    Local $sFile

    ; 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
        ; 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 <<<<<<<<<<<<<<<<<<<<<<<<<<

        ; Check if a folder
        If @extended Then
            ; If so then call the function recursively
            ListFiles_ToTreeView($sSourceFolder & $sFile, _GUICtrlTreeView_AddChild($hTreeView, $hItem, $sFile))
        Else
            ; If a file than write path and name
            _GUICtrlTreeView_AddChild($hTreeView, $hItem, $sFile)
        EndIf
    WEnd

    ; Close search handle
    FileClose($hSearch)

EndFunc   ;==>ListFiles_ToTreeView

Now sigh and say of course, why didn't I try that? :)

-smartee

Link to comment
Share on other sites

  • 3 months later...

Yes, it is: just look for _GUICtrlTreeView_GetCount, _GUICtrlTreeView_GetState, FileRead, GuiCtrlCreateEdit, GuiCtrlSetData, GuiCtrlRead, FileOpen, FileWrite, FileClose in the Help file.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...