buymeapc Posted February 1, 2016 Share Posted February 1, 2016 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. expandcollapse popup#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 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 1, 2016 Moderators Share Posted February 1, 2016 (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 February 1, 2016 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
buymeapc Posted February 1, 2016 Author Share Posted February 1, 2016 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? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 1, 2016 Moderators Share Posted February 1, 2016 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now