从源文件夹创建文件列表

时间:2013-06-19 01:56:45

标签: autoit

请帮我介绍如何创建列表,可能来自arrayList。输入框是文件夹的源,其所有png文件都在数组列表中,并在GU中显示。感谢

#include <GuiConstantsEx.au3>
#include <File.au3>
#include <Array.au3>

;GUI
GUICreate("Automation", 300, 500)
$sourceFolder = GUICtrlCreateInput ("Source Folder" , 10, 10,280, 20 )
$add = GUICtrlCreateButton("Add", 10, 35, 75, 20)
$mylist = GUICtrlCreateList("", 10, 60, 280, 300)

$sourceFolder = ControlGetText("Automation", "", "Edit1")
Local $FileList = _FileListToArray($sourceFolder, "*.png")


    $msg = 0
    While $msg 
        $msg = GUIGetMsg()
        Select
            Case $msg = $add
                GUICtrlSetData($mylist,$FileList)
                Exit
        EndSelect
    WEnd

If $sourceFolder > 1 Then
   If @error = 1 Then
       MsgBox(0, "", "No Folders Found.")
       Exit
   EndIf
   If @error = 4 Then
       MsgBox(0, "", "No Files Found.")
       Exit
   EndIf
   $arrayFileList = _ArrayDisplay($FileList)
EndIf



; GUI MESSAGE LOOP
GUISetState(@SW_SHOW)
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

1 个答案:

答案 0 :(得分:2)

您的代码中存在很多问题。

  • 2个消息循环是非常糟糕的做法
  • 第一个消息循环永远不会启动,因为您拥有While $msg,并且之前将$msg设置为0
  • 您正在第一个消息循环之前读取源文件夹控件,因此它的值始终为"Source Folder",而不是您想要的目录。
  • 即使第一个消息循环确实运行,GUI也不会显示。

就你想做什么而言:它只是返回数组的For ... Next循环。

#include <GuiConstantsEx.au3>
#include <File.au3>
#include <Array.au3>

;GUI
GUICreate("Automation", 300, 500)
$sourceFolder = GUICtrlCreateInput("Source Folder", 10, 10, 280, 20)
$add = GUICtrlCreateButton("Add", 10, 35, 75, 20)
$mylist = GUICtrlCreateList("", 10, 60, 280, 300)


GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $add
            $sFolder = ControlGetText("Automation", "", "Edit1")
            Local $FileList = _FileListToArray($sFolder, "*.*")

            If @error = 1 Then
                MsgBox(0, "", "No Folders Found.")
                Exit
            EndIf
            If @error = 4 Then
                MsgBox(0, "", "No Files Found.")
                Exit
            EndIf

            For $i = 1 To $FileList[0]
                GUICtrlSetData($mylist, $FileList[$i])
            Next
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd