Jump to content

Create GUI buttons from ListToArray result

Recommended Posts


Hey guys

I hope you can get me in the right direction with this one:


It's pretty easy to get a list with a specific filetype, and show it with _ArrayDisplay

#include <File.au3>

Local $aFileList = _FileListToArray("C:\Test\", "*.txt")

_ArrayDisplay($aFileList, "Available text files")

But what if I want to create a GUI with a button for every available txt file, and name each button after the txt file?

Let's say I have 3 txt files in C:\Test\


Should end up with a GUI with 3 buttons lined up vertically:

[ file1 ]
[ file2 ]
[ file3 ]


I hope it makes sense :-)

Edited by david1337

Share this post

Link to post
Share on other sites
#include <File.au3>
#include <GUIConstants.au3>
#include <Array.au3>

Global $aButtonIds = _FileListToArray("C:\test\", "*.*", $FLTA_FILES)
Global $hGui = GUICreate("Edit Get Text", 400, 300)
Global $aButtons[_ArrayDelete($aButtonIds, 0)]

For $i = 0 to UBound($aButtonIds) - 1
    $aButtonIds[$i] = GUICtrlCreateButton($aButtonIds[$i], 10, 10 + ($i * 30), 100, 20)

GUISetState(@SW_SHOW, $hGui)

While (True)
    Local $iMsg = GUIGetMsg()
    Switch ($iMsg)
        Case $GUI_EVENT_CLOSE
            Exit 0
        Case Else
            For $i = 0 to UBound($aButtonIds) - 1
                If ($iMsg = $aButtonIds[$i]) Then
                    MsgBox("", "", "Button " & GUICtrlRead($aButtonIds[$i]) & " pressed")


  • Like 1

Share this post

Link to post
Share on other sites


Exactly what I was looking for! Thank you so much, I will learn from your code now :-)



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


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.