Sign in to follow this  
Followers 0
burger

Find File and Run

7 posts in this topic

I want to find an executable file and then run that file. The following code produces an error "Unable to execute the external program. Any ideas?

; Shows the filenames of all files in the current directory
$search = FileFindFirstFile(@DesktopDir & "\TD file downloads\*.exe")  

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

While 1
    $file = FileFindNextFile($search) 
    Run($file,@DesktopDir & "\TD file downloads\")
    If @error Then ExitLoop
    
    MsgBox(4096, "File:", $file)
WEnd

; Close the search handle
FileClose($search)

Share this post


Link to post
Share on other sites



Thanks. I realized that after posting.

Share this post


Link to post
Share on other sites

I want to find an executable file and then run that file. The following code produces an error "Unable to execute the external program. Any ideas?

; Shows the filenames of all files in the current directory
$search = FileFindFirstFile(@DesktopDir & "\TD file downloads\*.exe")  

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

While 1
    $file = FileFindNextFile($search) 
    Run($file,@DesktopDir & "\TD file downloads\")
    If @error Then ExitLoop
    
    MsgBox(4096, "File:", $file)
WEnd

; Close the search handle
FileClose($search)
If there is only one *.exe, it'll never be run, because FileFindFirstFile(0 already found it and FileFindNextFile() is looking for the second "find".

Share this post


Link to post
Share on other sites

There are 2 exe files in the directory. It runs neither one.

Share this post


Link to post
Share on other sites

Your error is due to calling Run() on a folder name:

Run($file,@DesktopDir & "\TD file downloads\")

This needs to point to the found exe.

Also, just use:

#include <File.au3>

$fileList = _FileListToArray ( @DesktopDir & "\TD file downloads\", "*.exe", 1)

If $fileList[0] Then

;Run first found instance

Run(@DesktopDir & "\TD file downloads\" & $fileList[1])

EndIf

Share this post


Link to post
Share on other sites

That works, thank you for your help.

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