【问题标题】:Create list of files from a source folder从源文件夹创建文件列表
【发布时间】:2013-06-19 01:56:45
【问题描述】:

请帮助我如何创建一个列表,可能来自一个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

【问题讨论】:

    标签: autoit


    【解决方案1】:

    您的代码中有很多问题。

    • 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-21
      相关资源
      最近更新 更多