Jump to content

Select File in Folder View


Recommended Posts

I want to select a file in src folder. But this code does not work. Can someone explain why it is not working?

ShellExecute('C:\Users\opc\Desktop\src')

Sleep(2000) ; Wait for the folder window to open

; Select the file in the folder
;ControlFocus(
ControlFocus("[CLASS:CabinetWClass]", "", "[CLASSNN:DirectUIHWND3]")
ControlCommand("[CLASS:CabinetWClass]", "", "[CLASSNN:DirectUIHWND3]", "SelectString", '10GB_1.bin')

 

Link to comment
Share on other sites

  • 2 weeks later...
On 6/7/2023 at 7:30 PM, ayu_2403 said:

I want to select a file in src folder. But this code does not work. Can someone explain why it is not working?

The code you provided is not working because the ShellExecute function is used to open a file or folder with its associated program, not to select a file in a folder.

To select a file in a folder using AutoIt, you can use the FileSelectFolder function to prompt the user to select a folder, and then use the FileFindFirstFile and ControlListView functions to select the desired file in the folder.

 

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>

Local $sFolderPath = FileSelectFolder("Select a folder", "")

If @error Then
    MsgBox($MB_OK, "Error", "No folder selected.")
    Exit
EndIf

Local $sFileName = "10GB_1.bin"

Local $hSearch = FileFindFirstFile($sFolderPath & "\*")
If $hSearch = -1 Then
    MsgBox($MB_OK, "Error", "No files found in the selected folder.")
    Exit
EndIf

Local $sFile
While 1
    $sFile = FileFindNextFile($hSearch)
    If @error Then ExitLoop
    If StringCompare($sFile, $sFileName) = 0 Then ExitLoop
WEnd

FileClose($hSearch)

If Not StringCompare($sFile, $sFileName) = 0 Then
    MsgBox($MB_OK, "Error", "File '" & $sFileName & "' not found in the selected folder.")
    Exit
EndIf

Local $hWnd = WinGetHandle("[CLASS:CabinetWClass]")

ControlListView($hWnd, "", "SysListView321", "Select", $sFileName)

This example code assumes the folder window is of class [CLASS:CabinetWClass] and the file list view control has a class name of SysListView321. You may need to modify these values based on the specific application or window you are working with.

 

❤️

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...