autoit - 如何在目录中显示文件?

时间:2015-01-06 01:06:11

标签: autoit

我正在尝试显示位于目录中的文件列表。

这是我到目前为止的相关代码:

; Includes the GuiConstants (required for GUI function usage)
#include <GuiConstants.au3>
#include <File.au3>
#include <Array.au3>

Global $inputBox, $downloadsURL, $files

; Change to OnEvent mode
Opt('GUIOnEventMode', 1)

; GUI Creation
GuiCreate("Downloads Script", 400, 200)

; Runs the GUIExit() function if the GUI is closed
GUISetOnEvent($GUI_EVENT_CLOSE, 'GUIExit')


; Button1
GUICtrlCreateButton("Download File", -1, 60)
GUICtrlSetOnEvent(-1, 'runDownload') ; Runs function when pressed

Func runDownload()
$files = _FileListToArray("C:\Users\<user.name>\Pictures" , "*." , 1)
_ArrayDisplay($files)

EndFunc


; Shows the GUI after the function completes
GUISetState(@SW_SHOW)

; Idles the script in an infinite loop - this MUST be included when using OnEvent mode
While 1
   Sleep(500)
WEnd

; This function makes the script exit when the GUI is closed
Func GUIExit()
Exit
EndFunc

单击按钮后,没有任何反应。脚本只是永远运行....我错过了什么?

旁注...此脚本的长期目标是让它执行该特定目录中的任何文件...我是否可以将数组值传递给“运行”或“ ShellExecute“功能?

感谢您提供的任何帮助......非常感谢!

1 个答案:

答案 0 :(得分:1)

; Includes the GuiConstants (required for GUI function usage)
#include <GuiConstants.au3>
#include <File.au3>
#include <Array.au3>


Global $inputBox, $downloadsURL, $files


; Change to OnEvent mode
Opt('GUIOnEventMode', 1)


; GUI Creation
GUICreate("Downloads Script", 400, 200)
; Runs the GUIExit() function if the GUI is closed
GUISetOnEvent($GUI_EVENT_CLOSE, 'GUIExit')

; Button1
GUICtrlCreateButton("Download File", 0, 60)
GUICtrlSetOnEvent(-1, 'runDownload') ; Runs function when pressed

; Shows the GUI after the function completes
GUISetState(@SW_SHOW)


; Idles the script in an infinite loop - this MUST be included when using OnEvent mode
While 1
    Sleep(500)
WEnd

Func runDownload()
    $files = _FileListToArray(@UserProfileDir & "\Pictures", "*.*", 1)
    _ArrayDisplay($files)
EndFunc   ;==>runDownload

; This function makes the script exit when the GUI is closed
Func GUIExit()
    Exit
EndFunc   ;==>GUIExit