Jump to content

Selecting all files from the win explorer


Go to solution Solved by Luke94,

Recommended Posts

Posted

Hi,

I am new to AutoIt and i tried my best to find the solution. i have written the script for selecting a single file and uploading it, which is working fine with  ControlSetText("Open","","Edit1","D:\multi\t1.tif")

now i want to select all the file from the folder D:\multi, i have tried the below option but it does not work.

ControlFocus(" Open "," ","Edit1" )
Global $files="",$appendquotes="",$j=2;
IF $cmdLine[0]==1 then
    $files=$CmdLine[1]
 ElseIf $cmdLine[0] > 1 Then
   For $i=1 to $cmdLine[1]
       $appendquotes='"' & $CmdLine[$j] & '"';
       $files=$files & " " & $appendquotes;
       $j=$j+1;
    Next
EndIf

ControlSetText("Open","","Edit1","D:\multi")
Send( "^a" )
ControlClick("Open","","Button1")
 

sorry if the code is wrong, if anyone can help me it will means a lot to me.

Thank you.

Posted (edited)

Use _FileListToArrayRec to get a list of files in D:\multi as an array and then just loop through the list.

Basic example you can run within Scite:

#include <File.au3>
Global $g_sFolder = "D:\multi"
Global $g_aFileList = _FileListToArrayRec($g_sFolder, "*", 1, 0, 0, 2)
    If @error Then MsgBox(4096, "Error", 'No files found in "' & $g_sFolder & '"')
For $i = 1 To $g_aFileList[0]
    ConsoleWrite($g_aFileList[$i] & @CRLF)
Next

 

Edited by Subz
Posted
55 minutes ago, Subz said:

Use _FileListToArrayRec to get a list of files in D:\multi as an array and then just loop through the list.

Basic example you can run within Scite:

#include <File.au3>
Global $g_sFolder = "D:\multi"
Global $g_aFileList = _FileListToArrayRec($g_sFolder, "*", 1, 0, 0, 2)
    If @error Then MsgBox(4096, "Error", 'No files found in "' & $g_sFolder & '"')
For $i = 1 To $g_aFileList[0]
    ConsoleWrite($g_aFileList[$i] & @CRLF)
Next

 

Thank you very much sir, i tried to understand the code. but not sure how to send that array all together so that all the files get selected to upload. below is the screen shot that way i want to select. this is just 3 files which i can do with ControlSetText . but when its lets say 100 of files, i am unable to do code for that.

multiselect.PNG

Posted

So once you have a list you can just paste the results into the File name field for example (includes formating) "file1.ext" "file2.ext" "etc..".  You may need to change the Class/Instance depending on the program you're using.

#include <File.au3>
Global $g_sFolder = @ScriptDir;"D:\multi"
Global $g_aFileList = _FileListToArrayRec($g_sFolder, "*", 1)
    If @error Then MsgBox(4096, "Error", 'No files found in "' & $g_sFolder & '"')
ControlSetText("Open", "", "[CLASS:Edit; INSTANCE:1]", '"' & _ArrayToString($g_aFileList, '" "', 1, -1, '"') & '"')

 

Posted

How can i see the list of array i get, will ArrayDisplay($g_aFileList[$i] & @CRLF) this be useful? i tried but no luck

  • Solution
Posted (edited)

This should work? Assuming Edit1 is the correct ClassNameNN.

#include <File.au3>

ControlFocus(" Open "," ","Edit1" )
;~ Global $files="",$appendquotes="",$j=2;
;~ IF $cmdLine[0]==1 then
;~     $files=$CmdLine[1]
;~  ElseIf $cmdLine[0] > 1 Then
;~    For $i=1 to $cmdLine[1]
;~        $appendquotes='"' & $CmdLine[$j] & '"';
;~        $files=$files & " " & $appendquotes;
;~        $j=$j+1;
;~     Next
;~ EndIf

ControlSetText("Open","","Edit1",_Func("D:\multi"))
;~ Send( "^a" )
ControlClick("Open","","Button1")

Func _Func($sDir)
    Local $asFileList = _FileListToArrayRec($sDir, Default, $FLTAR_FILES, Default, Default, $FLTAR_FULLPATH)
    Local $sString = ''
    If @ERROR Then
        ConsoleWrite('Error: _FileListToArrayRec' & @CRLF)
    EndIf
    For $i = 1 To $asFileList[0] Step 1
        If $sString = '' Then
            $sString &= '"' & $asFileList[$i] & '"'
        Else
            $sString &= ' "' & $asFileList[$i] & '"'
        EndIf
    Next
    Return $sString
EndFunc

@Subz's _ArrayToString way is much prettier.

Edited by Luke94
Corrected the code. Global -> Local, $g_sDir -> $sDir
Posted
9 minutes ago, Disha said:

How can i see the list of array i get, will ArrayDisplay($g_aFileList[$i] & @CRLF) this be useful? i tried but no luck

_ArrayDisplay($g_aFileList)

Posted
15 hours ago, Luke94 said:

This should work? Assuming Edit1 is the correct ClassNameNN.

#include <File.au3>

ControlFocus(" Open "," ","Edit1" )
;~ Global $files="",$appendquotes="",$j=2;
;~ IF $cmdLine[0]==1 then
;~     $files=$CmdLine[1]
;~  ElseIf $cmdLine[0] > 1 Then
;~    For $i=1 to $cmdLine[1]
;~        $appendquotes='"' & $CmdLine[$j] & '"';
;~        $files=$files & " " & $appendquotes;
;~        $j=$j+1;
;~     Next
;~ EndIf

ControlSetText("Open","","Edit1",_Func("D:\multi"))
;~ Send( "^a" )
ControlClick("Open","","Button1")

Func _Func($sDir)
    Local $asFileList = _FileListToArrayRec($sDir, Default, $FLTAR_FILES, Default, Default, $FLTAR_FULLPATH)
    Local $sString = ''
    If @ERROR Then
        ConsoleWrite('Error: _FileListToArrayRec' & @CRLF)
    EndIf
    For $i = 1 To $asFileList[0] Step 1
        If $sString = '' Then
            $sString &= '"' & $asFileList[$i] & '"'
        Else
            $sString &= ' "' & $asFileList[$i] & '"'
        EndIf
    Next
    Return $sString
EndFunc

@Subz's _ArrayToString way is much prettier.

This works perfect, it passes the array string into the file name of win explorer but does not click on the open button, so the window does not close. could you please help me to look what could be the reason?

Posted

it worked by replacing ControlClick("Open","","Button1") this after the EndFunc. 

Thank you very much @Luke94 and @Subz  for helping me solve my query. you both made my day. Bless you both :)

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
  • Recently Browsing   0 members

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