Jump to content

Create A TreeView With Only Folders That Include Specific Files?


 Share

Recommended Posts

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

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

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