Sign in to follow this  
Followers 0
kevinz

How to display files within a directory? (and is it possible to pass array values into Run or ShellExecute functions?)

7 posts in this topic

I'm trying to display a list of files that are located within a directory.
This is the relevant code that I have so far:
 
; 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
 
After clicking the button, nothing happens. the script just runs forever.... What am I missing??
 
On a side note... long term goal for this script is for it to execute whatever file is located within that particular directory... Would it be possible for me to pass an array value into the "Run" or "ShellExecute" functions?
 
Also, I know that the "user.name" could cause issues, but I only changed it in the code above for privacy purposes...  
 
Thanks for any help you may be able to provide... it is appreciated!

Share this post


Link to post
Share on other sites



; 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


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Check the parameters of the functions you mentioned and see if the take arrays.

Loop through the array instead.

 

So I was able to get the list of files to populate into the array.

However I was not able to get the file from the array to execute.

I tried

ShellExecute($files[0])

and that didn't work..

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

[0] is the number of indexes in the array.

For $i = 1 To UBound($files) - 1
    ShellExecute($files[$i])
Next

Although, I'm unsure how you're going to manage opening a lot of "photos".

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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  
Followers 0