Retrieve folder contents, then put them into a DDL. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Ben the Coder

Retrieve folder contents, then put them into a DDL.  Topic is solved

Post by Ben the Coder » 09 Aug 2022, 11:25

Hi,
Is there a way to retrieve files from a folder (say A_WinDir\Fonts), then put the contents of the folder into a DropDownList?
Thanks!

User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Retrieve folder contents, then put them into a DDL.

Post by Xtra » 09 Aug 2022, 12:23

Example:

Code: Select all

Loop, Files, % A_WinDir . "\Fonts\*.*"
    fileList .= A_LoopFileName . "|"

Gui, Add, DropDownList, gSelectedFile vFileChoice, % RTrim(fileList, "|")
Gui, Show
return

SelectedFile:
    Gui, Submit, NoHide
    MsgBox, 4096, you selected, % FileChoice
return

Ben the Coder

Re: Retrieve folder contents, then put them into a DDL.

Post by Ben the Coder » 09 Aug 2022, 20:05

It works! :)
Incorporating it into my AHK script...

User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: Retrieve folder contents, then put them into a DDL.

Post by flyingDman » 09 Aug 2022, 20:22

I think that a DDL is somewhat of a dud when you have many items to list. It's not searchable so you have to scroll. A small listview is much more versatile and can be implemented together with a search box with just a few more lines of code:

Code: Select all

gui, add, text,x8, search:
gui, add, edit, x+10 y3 w105 gsearch vneedle
gui, add, listview, x8 y+2 w150 r5 vMyLV gpick -hdr,Files
gui, show
search:
gui, submit, nohide
lV_delete()
loop, files, % a_windir "\Fonts\*.*"
	if (instr(A_LoopFileName, needle))
		lv_add("", A_LoopFileName)
LV_ModifyCol(1,130)
return

pick:
lv_GetText(item, A_EventInfo,1)
msgbox % item
return
14.3 & 1.3.7

Ben the Coder

Re: Retrieve folder contents, then put them into a DDL.

Post by Ben the Coder » 10 Aug 2022, 09:36

Ok.
I'll try your suggestion now.

iPhilip
Posts: 817
Joined: 02 Oct 2013, 12:21

Re: Retrieve folder contents, then put them into a DDL.

Post by iPhilip » 11 Aug 2022, 01:30

flyingDman wrote:
09 Aug 2022, 20:22
I think that a DDL is somewhat of a dud when you have many items to list. It's not searchable so you have to scroll.
You might want to check out @teadrinker's searchable ComboBox (post).
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)

User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: Retrieve folder contents, then put them into a DDL.

Post by flyingDman » 11 Aug 2022, 11:37

@iPhilip Thanks. That's very clever but it does not match the versatility of the listview. After a small change in my script above, clicking on an item return the full path.

Code: Select all

gui, add, text,x8, search:
gui, add, edit, x+10 y3 w105 gsearch vneedle
gui, add, listview, x8 y+2 w150 r5 vMyLV gpick -hdr,Files|Path
gui, show
LV_ModifyCol(2,0)
search:
gui, submit, nohide
lV_delete()
loop, files, % a_windir "\Fonts\*.*"
	if (instr(A_LoopFileName, needle))
		lv_add("", A_LoopFileName,A_LoopFileFullPath)
LV_ModifyCol(1,130)
return

pick:
lv_GetText(item, A_EventInfo,2)
msgbox % item
return
14.3 & 1.3.7

Post Reply

Return to “Ask for Help (v1)”