HansSolo Posted November 27, 2018 Posted November 27, 2018 I'm quite new to Autoit. What I try to do is to open an explorer window and select the first file. That works good so far, using : _WinAPI_ShellOpenFolderAndSelectItems() I wanted to add some error handling to my code (see below) by checking/getting the selected file name. However, that seems to be quite challenging. #include <File.au3> #include <WinAPIShellEx.au3> ; Variables $username = EnvGet("username") $mdir = 'C:\Users\' & $username & '\Desktop\Downloads' ; Open Explorer Local $aList = _FileListToArray($mdir, '*', 1) If IsArray($aList) Then ; Select first file _WinAPI_ShellOpenFolderAndSelectItems($mdir, $aList, 1, 1) ; Open file by pressing <ENTER> $explorer = WinGetHandle("[TITLE:Downloads]") WinActivate($explorer) Send("{ENTER}") Can someone give me a hint how I can verify that the first file is selected in the specific folder before I press the ENTER key?
FrancescoDiMuro Posted November 27, 2018 Posted November 27, 2018 (edited) 10 minutes ago, HansSolo said: _WinAPI_ShellOpenFolderAndSelectItems($mdir, $aList, 1, 1) This function returns 0 in case of failure, and 1 in case of success. You could do something like: If _WinAPI_ShellOpenFolderAndSelectItems($mdir, $aList, 1, 1) Then ; Success ; ... Else ; Failure ; Error Handling EndIf Edited November 27, 2018 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
Subz Posted November 27, 2018 Posted November 27, 2018 You can do something like the following rather than using send keys: #include <Array.au3> #include <File.au3> Local $sDownloads = @DesktopDir & "\Downloads" If FileExists($sDownloads) = 0 Then Exit MsgBox(4096, "Folder Error", '"' & $sDownloads & '" could not be found.' & @CRLF & "Exiting Script") Local $aFileList = _FileListToArray($sDownloads, "*", 1) If @error Then Exit MsgBox(4096, "File List", "No Files found.") For $i = 1 To $aFileList[0] ShellExecute($sDownloads & "\" & $aFileList[$i]) Next
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now