Disha Posted June 9, 2021 Share Posted June 9, 2021 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. Link to comment Share on other sites More sharing options...
Subz Posted June 9, 2021 Share Posted June 9, 2021 (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 June 9, 2021 by Subz Link to comment Share on other sites More sharing options...
Disha Posted June 9, 2021 Author Share Posted June 9, 2021 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. Link to comment Share on other sites More sharing options...
Subz Posted June 9, 2021 Share Posted June 9, 2021 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, '"') & '"') Link to comment Share on other sites More sharing options...
Disha Posted June 9, 2021 Author Share Posted June 9, 2021 How can i see the list of array i get, will ArrayDisplay($g_aFileList[$i] & @CRLF) this be useful? i tried but no luck Link to comment Share on other sites More sharing options...
Solution Luke94 Posted June 9, 2021 Solution Share Posted June 9, 2021 (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 June 9, 2021 by Luke94 Corrected the code. Global -> Local, $g_sDir -> $sDir Link to comment Share on other sites More sharing options...
Luke94 Posted June 9, 2021 Share Posted June 9, 2021 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) Link to comment Share on other sites More sharing options...
Disha Posted June 10, 2021 Author Share Posted June 10, 2021 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? Link to comment Share on other sites More sharing options...
Disha Posted June 10, 2021 Author Share Posted June 10, 2021 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 Link to comment Share on other sites More sharing options...
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