Jump to content

List all files in a folder in a List Control


 Share

Recommended Posts

Hi

I need to use a List control to display all files in a folder so that later, when a user highlights an item and clicks a button control, that particular file will load.

I know this is similar to using the FileOpenDialog, but that is not what I want to do.

Any help is appreciated. Here is what I go so far. It will list all zip files in a folder but then empty itself out.

#Include <GUIConstants.au3>

$search = FileChangeDir("C:\somefolder")
$search = FileFindFirstFile("*.zip")  

If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

GuiCreate("Test", 600, 600,-1, -1)
$list = GuiCtrlCreateList("", -1, -1, 600,600)
GUICtrlSetFont (-1,20,400,0,"Arial Bold")

GUISetState()
While 1
$msg = GUIGetMsg()
   If $msg = $GUI_EVENT_CLOSE Then Exit
    $file = FileFindNextFile($search)
    GUICtrlSetData($list, $file)
WEnd
FileClose($search)

Thanks,

Steve

Link to comment
Share on other sites

Hi all,

I got it working. :idiot: Here is the code.

#include <GUIConstants.au3>
#include <_FileSearch.au3>

;search
$path = "C:\somefolder\"
$alpha = _FileSearch($path,0,"",1)

;GUI
$guiwidth = @DesktopWidth/2
$guiheight = @DesktopHeight/2

$gui = GUICreate("list files",$guiwidth,$guiheight,-1,-1,$WS_SIZEBOX+$WS_MINIMIZEBOX+$WS_MAXIMIZEBOX)
GuiSetState(@SW_SHOW)

$tv = GuiCtrlCreateList("",-1, -1, $guiwidth, $guiheight-20)

For $i = 1 to $alpha[0]
     $alpha[$i] = StringReplace($alpha[$i], $path, "")
                 GuiCtrlSetData($tv,$alpha[$i])
Next

While 1

$msg = GuiGetMsg()

   Select
   
   Case $msg = $GUI_EVENT_CLOSE 
           ExitLoop     
  
  EndSelect
WEnd

L8tr,

Steve

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...