Jump to content
Sign in to follow this  

_FileListToArray to GUI List

Recommended Posts


Does anyone now how to create a list (using a GUI) of the files on the desktop (or other folder. it doesn't matter)?

I don't understand arrays in AutoIt or much anywhere else, so this is my best shot

$totalFileAmount = _ArrayMaxIndex($FileList, 1, 1)
GuiCtrlCreateList("", 5, 190, 100, 90)
Dim $avArray[$totalFileAmount], $I = 0
MsgBox(0,'Max Index Numeric value',_ArrayMaxIndex($FileList, 1, 1))
For $I = 0 to UBound( $avArray ) - 1
    $avArray[$I] = GuiCtrlSetData(-1, $totalFileAmount)

A decision is a powerful thing

Share this post

Link to post
Share on other sites

you're making it more difficult on yourself that you should. Here are a few pointers

the first vector of $FileList is the number of files/folders found. Basically, this means that the function _ArrayMaxIndex isn't necessary.

just stating the obvious, in case you didn't know (it wasn't included in your code snippet in your first post) but before you can list the entries in a GUI, you need to create the GUI using GuiCreate. I won't show you the syntax, because I will assume that you already know it or can look it up in the helpfile. Next create a ListBox, or some other control of your choice (this part was in your code... you will want to get the handle of the control when you create it, though, so that you can create additional controls and use them all. change GuiCtrlCreateList("", 5, 190, 100, 90) to $MyList=GuiCtrlCreateList("", 5, 190, 100, 90))

Then set the data in a for-next loop. Something like this should work for you

local $FileList=_FileListToArray(@DesktopDir)
$MyGui=GUICreate("File List")
$MyList=GuiCtrlCreateList("", 5, 190, 100, 90); I didn't adjust the coordinates... go ahead and play around with them
For $I = 1 to $FileList[0]
    GuiCtrlSetData($MyList, $FileList[$i])
sleep(10000);so you have time to see the GUI before the script closes

This is untested, as I just wrote it in the Browser, but it should do the job

Edit: Don't get me wrong, it was very resourceful of you to find the function _ArrayMaxIndex() and attempt to use it. Anyway, simpler is better. And this is much simpler.

Edited by improbability_paradox

Share this post

Link to post
Share on other sites

improbability_paradox, thanks! That works great! Oh, and thanks for pointing out the "obvious." I did know about that, but if I didn't it would have drove me nuts. You're right what you wrote was not only simpler, but easier to understand. Thanks also for the encouragement about the ArrayMaxIndex.

A decision is a powerful thing

Share this post

Link to post
Share on other sites

Try this:

#include <File.au3>
#Include <GuiList.au3>
Global $FileList
GUICreate("File List GUI", 400, 400)
$MyGui = GUICreate("File List")
$MyList = GUICtrlCreateList("", 5, 5, 300, 90)
If Not _FileReadToArray("test.txt", $FileList) Then
    MsgBox(4096, "Error", " Error reading log to Array     error:" & @error)
For $i = 1 To $FileList[0]
    _GUICtrlListAddItem($MyList, $FileList[$i])

Hope it helps :)

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
Sign in to follow this