Added: If you pass a list of drive letters in the $sRoot paramenter, _CFF_Choose will display only these drives in the drive combo at the top of the dialog - any invalid drive letters will be ignored. If you want one of these drives to be loaded automatically, then add "|drive_letter" after the list. Passing just "|drive_letter" in the parameter (with no drive list) automatically loads that drive and all ready drives will be displayed in the combo. See Example_3 script for more details.
This is a non-scriptbreaking change. Thanks to Tankbuster for the request.
New UDF and a new example below and in the zip.
Previous versions:
Spoiler
New version 28 May 13
Added: Pressing the Ctrl key while selecting will remove the item (or its last instance - see below) from the return list.
Changed: By default the same item cannot now be selected multiple times - but by adding + 32 to the $iDisplay parameter this becomes possible.
Thanks to lhk69 for the requests.
New version 22 May 13
Added: When both files and folders are displayed, the user can choose just files or both files AND folders. Just add +16 to the $iDisplay parameter. Thanks to lhk69 for the request.
New version 19 Dec 2012
Changed: The action taken when doubleclicking on a folder only tree when $iDisplay is set to 3 has changed slightly. Now the item is expanded/contracted if there are children, but selected if there are none. The previous version never selected items on doubleclick, only via the "Select" button - which of course will still select the item regardless of whether children exist.
New version 2 Dec 2012
Changed: Added the ability to both include and exclude files/folders from the tree. The $sMask parameter can now have 3 sections (separated by " | ") which define what to include, exclude and (if you are displaying both files and folders) which folders to exclude. See the RecFileListToArray thread (look in the first spoiler) for more details on exactly how these parameters affect the displayed tree.
Note: You will need the new version of my RecFileListToArray UDF. Look in that UDF thread for the new code.
New version 12 Oct 2012
Added: A new function _CFF_Embed which creates the folder tree in an existing treeview within your own GUI rather than having to use a UDF-created dialog. Thanks to Syed23 for the suggestion.
Changed: Script breaking change to $iDisplay parameter syntax in _CFF_Choose - add 64 not 16 to hide file extensions. This was done as new versions of _RecFileListToArray (which is needed to run the UDF) will have additional options which use the current value. Sorry about the change, but I am trying to future-proof as much as I can.
New version 4 Oct 2012
This is a completely rewritten version of the UDF with script-breaking syntax changes. It now develops the tree dynamically and is very much faster than previous versions. It also uses the new version of my RecFileListToArray UDF to allow you to either show or hide hidden and system files/folders. Warning: There are script-breaking changes - read the _CFF_Choose function header to see how the $iDisplay parameter is now set - and you always need to register the WM_NOTIFY if you use the UDF.
My thanks to caleb41610 for the thread which sparked the idea - and especially guinness for help with the #*@#*%# Struct !!!!
BugFix version - 16 Dec 11
- Fixed: Rapid clicking on the TreeView expand/contract icons could be treated as a double click and so trigger an inadvertant selection. Now double clicks are ignored for a short period after the TreeView is expanded/contracted. Thanks WPA-Fan for pointing it out.
[NEW VERSION] - 23 May 11 - Warning: Script breaking syntax and function name changes
Changes:
- Added new option to display "files & only those folders containing files".
Option 0 will display all folders in the tree regardless of whether they hold matching files.
Option 3 displays only those folders which contain files of the matching type - empty folders are not displayed unless they hold subfolders containing files. See Ex 1 and 2 in the example script.
- Syntax change when using _CFF_IndexDefault to preload folders and/or files for speed.
- Load separate "files" and "folders" defaults or a combined "files and folders" default. All 3 can be set independently. See Function header notes for details.[/indent]
- New functions to set existing arrays as defaults.
_CFF_SetDefault replaced by:
_CFF_SetDefault_Folder: Sets existing array as default folder index for speed
_CFF_SetDefault_File: Sets existing array as default file index for speed
_CFF_SetDefault_Combo: Sets existing array as default folder and file index for speed
See Function header notes for details of how arrays must be created.
This version requires the latest version of RecFileListToArray - see my sig below or in the zip.
Sorry for the script breaking nature of this version - I hope anyone who uses it feels the changes were worth it.
[BUGFIX VERSION] - 18 Feb 11
Fixed: Bug which prevented selection of files when a drive had to be selected and multiple file extensions were possible but not displayed.
No need to adjust existing scripts.
[NEW VERSION] - 16 Feb 11
Changes:
- Added option to display files without extensions - although the extensions are still in the returned file paths.
- Just add 4 to the normal $iDisplay parameter. Note this option is not available if you use a .* wildcard in the $sFile_Mask parameter - if you do, how is the UDF supposed to know what extension to return?
- I did this so I could display a listing of .mp3 files in my music player without all of them showing the .mp3 extension - if I am choosing a track I know they are all .mp3 files!
No need to adjust existing scripts - just use the option if you want to.
[NEW VERSION] - 11 Feb 11
Changes:
- Now x64 comaptible - thanks Ascend4nt and Yashied.
- Now fully OnEvent mode compatible - I missed out a line last time.
- Minor code changes - no need to adjust existing scripts.
New version 28 May 13
Added: Pressing the Ctrl key while selecting will remove the item (or its last instance - see below) from the return list.
Changed: By default the same item cannot now be selected multiple times - but by adding + 32 to the $iDisplay parameter this becomes possible.
Thanks to lhk69 for the requests.
New version 22 May 13
Added: When both files and folders are displayed, the user can choose just files or both files AND folders. Just add +16 to the $iDisplay parameter. Thanks to lhk69 for the request.
New version 19 Dec 2012
Changed: The action taken when doubleclicking on a folder only tree when $iDisplay is set to 3 has changed slightly. Now the item is expanded/contracted if there are children, but selected if there are none. The previous version never selected items on doubleclick, only via the "Select" button - which of course will still select the item regardless of whether children exist.
New version 2 Dec 2012
Changed: Added the ability to both include and exclude files/folders from the tree. The $sMask parameter can now have 3 sections (separated by " | ") which define what to include, exclude and (if you are displaying both files and folders) which folders to exclude. See the RecFileListToArray thread (look in the first spoiler) for more details on exactly how these parameters affect the displayed tree.
Note: You will need the new version of my RecFileListToArray UDF. Look in that UDF thread for the new code.
New version 12 Oct 2012
Added: A new function _CFF_Embed which creates the folder tree in an existing treeview within your own GUI rather than having to use a UDF-created dialog. Thanks to Syed23 for the suggestion.
Changed: Script breaking change to $iDisplay parameter syntax in _CFF_Choose - add 64 not 16 to hide file extensions. This was done as new versions of _RecFileListToArray (which is needed to run the UDF) will have additional options which use the current value. Sorry about the change, but I am trying to future-proof as much as I can.
New version 4 Oct 2012
This is a completely rewritten version of the UDF with script-breaking syntax changes. It now develops the tree dynamically and is very much faster than previous versions. It also uses the new version of my RecFileListToArray UDF to allow you to either show or hide hidden and system files/folders. Warning: There are script-breaking changes - read the _CFF_Choose function header to see how the $iDisplay parameter is now set - and you always need to register the WM_NOTIFY if you use the UDF.
My thanks to caleb41610 for the thread which sparked the idea - and especially guinness for help with the #*@#*%# Struct !!!!
BugFix version - 16 Dec 11
- Fixed: Rapid clicking on the TreeView expand/contract icons could be treated as a double click and so trigger an inadvertant selection. Now double clicks are ignored for a short period after the TreeView is expanded/contracted. Thanks WPA-Fan for pointing it out.
[NEW VERSION] - 23 May 11 - Warning: Script breaking syntax and function name changes
Changes:
- Added new option to display "files & only those folders containing files".
- $iDisplay - 0 - Display full folder tree and matching files (default) 1 - Display all matching files within the specified folder - subfolders are not displayed 2 - Display folder tree only - no files NEW - 3 - Display only those folders containing matching files and the files within them + 4 - Do not display file extensions in tree (ignored if .* ext in $sFile_Mask)
Option 3 displays only those folders which contain files of the matching type - empty folders are not displayed unless they hold subfolders containing files. See Ex 1 and 2 in the example script.
- Syntax change when using _CFF_IndexDefault to preload folders and/or files for speed.
- Load separate "files" and "folders" defaults or a combined "files and folders" default. All 3 can be set independently. See Function header notes for details.[/indent]
- New functions to set existing arrays as defaults.
_CFF_SetDefault replaced by:
_CFF_SetDefault_Folder: Sets existing array as default folder index for speed
_CFF_SetDefault_File: Sets existing array as default file index for speed
_CFF_SetDefault_Combo: Sets existing array as default folder and file index for speed
See Function header notes for details of how arrays must be created.
This version requires the latest version of RecFileListToArray - see my sig below or in the zip.
Sorry for the script breaking nature of this version - I hope anyone who uses it feels the changes were worth it.
[BUGFIX VERSION] - 18 Feb 11
Fixed: Bug which prevented selection of files when a drive had to be selected and multiple file extensions were possible but not displayed.
No need to adjust existing scripts.
[NEW VERSION] - 16 Feb 11
Changes:
- Added option to display files without extensions - although the extensions are still in the returned file paths.
- Just add 4 to the normal $iDisplay parameter. Note this option is not available if you use a .* wildcard in the $sFile_Mask parameter - if you do, how is the UDF supposed to know what extension to return?
- I did this so I could display a listing of .mp3 files in my music player without all of them showing the .mp3 extension - if I am choosing a track I know they are all .mp3 files!
No need to adjust existing scripts - just use the option if you want to.
[NEW VERSION] - 11 Feb 11
Changes:
- Now x64 comaptible - thanks Ascend4nt and Yashied.
- Now fully OnEvent mode compatible - I missed out a line last time.
- Minor code changes - no need to adjust existing scripts.
I was fed up with using the native FileOpenDialog and FileSelectFolder which appeared anywhere on the screen in seemingly random sizes and often allowed users to select files from other than the path desired. So I decided to write my own version of an Explorer-type treeview and here it is: ChooseFileFolder.
What are the main advantages of this UDF over the normal dialogs?
- Common format for both file and folder selection.
- Ability to size and place the dialog where you want it rather than how Windows last left it.
- Ability to select (and delete) multiple items - even from different folders or drives. You can also select both files and folders from the same tree.
And there is also a function to allow you to use an existing treeview in your own GUI to display the folder tree - no need to have a dialog at all.
[New] Here is a short example script which shows the ChooseFileFolder UDF dialog in action showing how its parameters define different tree display and selection options:
Spoiler
AutoIt
#include "ChooseFileFolder.au3" Local $sRet, $aRet Local $sRootFolder = StringRegExpReplace(@AutoItExe, "(^.*\\)(.*)", "\1") ; Register WM_NOTIFY handler $sRet = _CFF_RegMsg() If Not $sRet Then MsgBox(16, "Failure!", "Handler not registered") Exit EndIf MsgBox(64, "Example Script 1", "Please read the comments for each Example as it runs" & @CRLF & "to see how the display and return values have been set") ; Pick a single folder from within the AutoIt installation folders ; Select using the "Select" button only - doubleclick expands by does not select item ; Make the final parameter 3 if you want to use doubleclick as well - but beware when clicking on the items! $sRet = _CFF_Choose("Ex 1: Choose a folder", 300, 500, -1, -1, $sRootFolder, "*", 2) If $sRet Then MsgBox(64, "Ex 1", "Selected:" & @CRLF & @CRLF & $sRet) Else MsgBox(64, "Ex 1", "No Selection") EndIf ; Pick a single *.au3 or *.ico file from within the AutoIt installation folders ; All folders are displayed whether they contain files or not ; Use either the "Select" button or a double click - only files can be selected $sRet = _CFF_Choose("Ex 2: Choose a file", 300, 500, -1, -1, $sRootFolder, "*.au3;*.ico") If $sRet Then MsgBox(64, "Ex 2", "Selected:" & @CRLF & @CRLF & $sRet) Else MsgBox(64, "Ex 2", "No Selection") EndIf ; Pick any file on any drive ; Hidden and system files/folders will be shown - compare with next example $sRet = _CFF_Choose("Ex 3: Select a file", 300, 500) If $sRet Then MsgBox(64, "Ex 3", "Selected:" & @CRLF & @CRLF & $sRet) Else MsgBox(64, "Ex 3", "No Selection") EndIf ; Pick multiple files from any drive - list takes 20% of dialog ; Play with the final parameter to change that percentage ; Hidden and system files/folders will not be shown ( + 4 + 8) ; Multiple instances of the same item allowed ( + 32) ; Use either the "Add" button or a double click to add to the list - only files can be added ; If Ctrl key pressed as item selected, last instance of item is removed from list ; Press "Return" button when selection ended to get "|" delimited string of selected files $sRet = _CFF_Choose("Ex 4: Select multiple files (duplicates allowed)", 300, 500, -1, -1, "", Default, 0 + 4 + 8 + 32, 20) If $sRet Then $aRet = StringSplit($sRet, "|") $sRet = "" For $i = 1 To $aRet[0] $sRet &= $aRet[$i] & @CRLF Next MsgBox(64, "Ex 4", "Selected:" & @CRLF & @CRLF & $sRet) Else MsgBox(64, "Ex 4", "No Selection") EndIf ; As above but with the ability to choose files AND folders (+ 16) ; Multiple instances not permitted (Not + 32) ; Beware when double clicking on the folders - it expands but also selects them! ; Selected folders have a trailing "\" added $sRet = _CFF_Choose("Ex 5: Select multiple files AND folders", 300, 500, -1, -1, "", Default, 0 + 4 + 8 + 16, 20) If $sRet Then $aRet = StringSplit($sRet, "|") $sRet = "" For $i = 1 To $aRet[0] $sRet &= $aRet[$i] & @CRLF Next MsgBox(64, "Ex 5", "Selected:" & @CRLF & @CRLF & $sRet) Else MsgBox(64, "Ex 5", "No Selection") EndIf ; Choose a single file from a specified folder - no subfolders displayed ; Note file exts displayed because of *.* mask even though requested to be hidden (+ 64) $sRet = _CFF_Choose("Ex 6: Select a file", 300, 500, -1, -1, $sRootFolder, "*.*", 1 + 64) If $sRet Then MsgBox(64, "Ex 6", "Selected:" & @CRLF & @CRLF & $sRet) Else MsgBox(64, "Ex 6", "No Selection") EndIf ; Choose a single file from a specified folder - no subfolders displayed ; Note file exts hidden, but returned (+ 64) $sRet = _CFF_Choose("Ex 7: Select a file - no extensions displayed", 300, 500, -1, -1, $sRootFolder & "Include\", "*.au3", 1 + 64) If $sRet Then MsgBox(64, "Ex 7 - But extension returned", "Selected:" & @CRLF & @CRLF & $sRet) Else MsgBox(64, "Ex 7", "No Selection") EndIf
Here is an example showing the UDF being used with existing controls in separate GUI:
Spoiler
AutoIt
#include <GUIConstantsEx.au3> #include "ChooseFileFolder.au3" Global $aDrives = DriveGetDrive("ALL") Global $sDrives = "" For $i = 1 To $aDrives[0] ; Only display ready drives If DriveStatus($aDrives[$i] & '\') <> "NOTREADY" Then $sDrives &= "|" & StringUpper($aDrives[$i]) Next ; Register UDF message handler _CFF_RegMsg() ; Create GUI $hGUI = GUICreate("_CFF_Embed Example - only one TreeView active at one time", 750, 560) GUISetBkColor(0xC4C4C4) ; Native TreeView - single selection GUICtrlCreateLabel("Choose Drive", 10, 10, 90, 20) $cCombo_Single = GUICtrlCreateCombo("", 100, 10, 60, 20) GUICtrlSetData(-1, $sDrives) GUICtrlCreateLabel("Single selection", 10, 40, 200, 20) $cTV_Single = GUICtrlCreateTreeView(10, 60, 230, 440) $sText = "Select" & @TAB & "= Doubleclick or Singleclick + ENTER" & @CRLF & "Cancel" & @TAB & "= ESCAPE" GUICtrlCreateLabel($sText, 10, 510, 230, 60) ; native TreeView - multiple selection (duplicates allowed) with list control, but no return control GUICtrlCreateLabel("Choose Drive", 260, 10, 90, 20) $cCombo_Multi_List = GUICtrlCreateCombo("", 350, 10, 60, 20) GUICtrlSetData(-1, $sDrives) GUICtrlCreateLabel("Multiple (duplicate) selection with list", 260, 40, 200, 20) $cTV_Multi_List = GUICtrlCreateTreeView(260, 60, 230, 330) $cList_Multi_List = GUICtrlCreateList("", 260, 400, 230, 100) $sText = "Select" & @TAB & "= Doubleclick" & @CRLF & "Return" & @TAB & "= ENTER" & @CRLF & "Cancel" & @TAB & "= ESCAPE" GUICtrlCreateLabel($sText, 260, 510, 230, 60) ; UDF TreeView - multiple selection with no list control GUICtrlCreateLabel("Choose Drive", 510, 10, 90, 20) $cCombo_Multi_NoList = GUICtrlCreateCombo("", 600, 10, 60, 20) GUICtrlSetData(-1, $sDrives) GUICtrlCreateLabel("Multiple selection with 'Return' button", 510, 40, 200, 20) $hTV_Multi_NoList = _GUICtrlTreeView_Create($hGUI, 510, 60, 230, 400, BitOr($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS)) $cStop_Multi_NoList = GUICtrlCreateButton("Return", 510, 470, 230, 30) $sText = "Select" & @TAB & "= Doubleclick" & @CRLF & "Return" & @TAB & "= ENTER or 'Return' button" & @CRLF & "Cancel" & @TAB & "= ESCAPE" GUICtrlCreateLabel($sText, 510, 510, 230, 60) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cCombo_Single ; Disable combos - function is blocking so only one TreeView at a time can be used GUICtrlSetState($cCombo_Single, $GUI_DISABLE) GUICtrlSetState($cCombo_Multi_List, $GUI_DISABLE) GUICtrlSetState($cCombo_Multi_NoList, $GUI_DISABLE) $sRoot = GUICtrlRead($cCombo_Single) & "\" ; No return Control specified, so only single selection $sSel = _CFF_Embed($cTV_Single, $sRoot, "*.*", 12) ConsoleWrite(@error & " - " & @extended & " - " & $sSel & @CRLF) ; Re-enable combos GUICtrlSetData($cCombo_Single, $sDrives) GUICtrlSetState($cCombo_Single, $GUI_ENABLE) GUICtrlSetState($cCombo_Multi_List, $GUI_ENABLE) GUICtrlSetState($cCombo_Multi_NoList, $GUI_ENABLE) Case $cCombo_Multi_List GUICtrlSetState($cCombo_Single, $GUI_DISABLE) GUICtrlSetState($cCombo_Multi_List, $GUI_DISABLE) GUICtrlSetState($cCombo_Multi_NoList, $GUI_DISABLE) $sRoot = GUICtrlRead($cCombo_Multi_List) & "\" ; $iDisplay + 32 so duplicate selections allowed ; $iReturn <> 0 so multiple selection list ; List control specified so selections displayed $sSel = _CFF_Embed($cTV_Multi_List, $sRoot, "*.*", 12 + 32, 1, $cList_Multi_List) ConsoleWrite(@error & " - " & @extended & " - " & $sSel & @CRLF) GUICtrlSetData($cCombo_Multi_List, $sDrives) GUICtrlSetState($cCombo_Single, $GUI_ENABLE) GUICtrlSetState($cCombo_Multi_List, $GUI_ENABLE) GUICtrlSetState($cCombo_Multi_NoList, $GUI_ENABLE) Case $cCombo_Multi_NoList GUICtrlSetState($cCombo_Single, $GUI_DISABLE) GUICtrlSetState($cCombo_Multi_List, $GUI_DISABLE) GUICtrlSetState($cCombo_Multi_NoList, $GUI_DISABLE) $sRoot = GUICtrlRead($cCombo_Multi_NoList) & "\" ; Return control specified so multiple selections $sSel = _CFF_Embed($hTV_Multi_NoList, $sRoot, "*.*", 12, $cStop_Multi_NoList) ConsoleWrite(@error & " - " & @extended & " - " & $sSel & @CRLF) GUICtrlSetData($cCombo_Multi_NoList, $sDrives) GUICtrlSetState($cCombo_Single, $GUI_ENABLE) GUICtrlSetState($cCombo_Multi_List, $GUI_ENABLE) GUICtrlSetState($cCombo_Multi_NoList, $GUI_ENABLE) EndSwitch WEnd
[New] And an example showing how to use the new folder list functionality (you will need to amend the letter to match your system
Spoiler
AutoIt
#include "ChooseFileFolder.au3" Local $sRet Local $sRootFolder = StringRegExpReplace(@AutoItExe, "(^.*\\)(.*)", "\1") ; Register WM_NOTIFY handler $sRet = _CFF_RegMsg() If Not $sRet Then MsgBox(16, "Failure!", "Handler not registered") Exit EndIf ; All ready drives - no default _CFF_Choose("Ex 1: All drives with no default", 300, 500) ConsoleWrite("Ex 1: " & @error & @CRLF) ; Limit to certain drives - note only ready drives are displayed in the combo _CFF_Choose("Ex 2: Drive list with no default", 300, 500, -1, -1, "acmnxyz") ; Add some random letters to check <<<<<<<<<<<<<<<<<<<<<<<<<< ConsoleWrite("Ex 2: " & @error & @CRLF) ; Open the default drive of a set _CFF_Choose("Ex 3: Drive list with default", 300, 500, -1, -1, "cmn|n") ConsoleWrite("Ex 3: " & @error & @CRLF) ; Open the default drive and show all drives in combo _CFF_Choose("Ex 4: All drives with default", 300, 500, -1, -1, "|n") ConsoleWrite("Ex 4: " & @error & @CRLF) ; This should fail with error 1 - Path does not exist or invalid drive list _CFF_Choose("Ex 5", 300, 500, -1, -1, "C:\Fr|ed\") ; Invalid path ConsoleWrite("Ex 5: " & @error & @CRLF) ; This should fail with error 1 - Path does not exist or invalid drive list _CFF_Choose("Ex 6", 300, 500, -1, -1, "cde5") ; Digit in drive list ConsoleWrite("Ex 6: " & @error & @CRLF) ; This should fail with error 1 - Path does not exist or invalid drive list _CFF_Choose("Ex 7", 300, 500, -1, -1, "|cde") ; Multiple defaults ConsoleWrite("Ex 7: " & @error & @CRLF) ; The default drive not in drive list and so is ignored _CFF_Choose("Ex 8: Default not in drive list", 300, 500, -1, -1, "cde|f") ; Default drive not in drive list ConsoleWrite("Ex 8: " & @error & @CRLF) ; The chosen default drive does not exist and so is ignored _CFF_Choose("Ex 9: Default drive not ready", 300, 500, -1, -1, "cdez|z") ConsoleWrite("Ex 9: " & @error & @CRLF)
[New] The ChooseFileFolder UDF itself is now too large to fit within code tags - it is in the zip below.
You will need my RecFileListToArray UDF to run ChooseFileFolder - you can find it in my sig and it is included in this zip file with the examples and UDF:
ChooseFileFolder.zip 18.78KB
49 downloadsAs usual happy to take feedback and, preferably, plaudits.
M23
Edited by Melba23, 14 June 2013 - 12:43 PM.





