buymeapc

Create A TreeView With Only Folders That Include Specific Files?

4 posts in this topic

Hey all,

So, I've been wracking my head against what seems to be a very simple thing, but I just can't get the desired outcome here. I'm trying to get a list of a specific file type (*.config) and display the files in a treeview where you can drill down through the folders in the treeview to the files. Below is an example from the forums (from spudw2k) that gives me almost what I want, but I don't want to display the empty folders - that's where I'm stuck.

How can I display the treeview structure without including the folders that contain any of the specified file type??

Thanks for your help.

#include <GUIConstantsEx.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiTreeView.au3>
#Include <File.au3>

$winX = @DesktopWidth * .35
$winY = @DesktopHeight * .375
$gui = GUICreate("File Browser", $winX, $winY, -1, -1, $WS_SIZEBOX)
$tree = GUICtrlCreateTreeView(0, 0, $winX * .9965, $winY * .91125)
GUICtrlSetFont(-1, $winX * .0275)

GUICtrlSetColor($tree, 0x00FF00)
GUICtrlSetBkColor($tree, 0x000000)
GUISetState(@SW_SHOW)

$root = _GUICtrlTreeView_AddChild($tree, "", "MainFolder")
_SearchFolder("C:\Users\test\Desktop\FolderWithConfigFiles", $root)

While 1
    $msg = GUIGetMsg()
    If $msg= -3 Then ExitLoop
WEnd

Func _SearchFolder($folder, $parent)
    $files = _FileListToArray($folder,"web.config", $FLTAR_FILES)
    $folders = _FileListToArray($folder,"*", $FLTAR_FOLDERS)
    _FolderFunc($folders, $folder, $parent)
    _FileFunc($files, $parent)
EndFunc

Func _FileFunc($files, $parent)
    For $i = 1 To UBound($files)-1
        _GUICtrlTreeView_AddChild($tree, $parent, $files[$i])
    Next
EndFunc

Func _FolderFunc($folders, $parentdir, $parent)
    For $i = 1 To UBound($folders)-1
        $parentitem = _GUICtrlTreeView_AddChild($tree, $parent, $folders[$i])
        _SearchFolder($parentdir & "\" & $folders[$i], $parentitem)
    Next   
EndFunc

 

2-1-2016 10-36-47 AM.png

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

buymeapc,

I came across the same problem when writing my ChooseFileFolder UDF. If you want to remove the empty folders from the list of those to display, you need to expand the whole tree first to determine which are empty - this can be very, very slow for large trees. When I was asked to incorporate this feature in the UDF you can follow the very similar discussion here:

https://www.autoitscript.com/forum/topic/125293-choosefilefolder-bugfix-version-11-jun-15/?do=findComment&comment=1266806

So I would suggest leaving things as they are.

M23

Edited by Melba23
Added a bit

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share this post


Link to post
Share on other sites

Hmm...that's unfortunate. Do you think there might be any way to do it by using _FileListToArrayRec to get a list of files and create the treeview items that way?

Share this post


Link to post
Share on other sites

buymeapc,

Of course, that is what I did in the first versions of the UDF. But that still entails reading the whole tree to determine which folders have the required content, so it is pretty slow for large trees.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share this post


Link to post
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