Sign in to follow this  
Followers 0
nbala75

Better way to select file(s) ?

12 posts in this topic

Right now iam doing it like this. Is there a better way to do this? This is during a data import process.

Posted Image

Posted Image

Posted Image

Posted Image

Share this post


Link to post
Share on other sites



Use ControlSend() to send Shortcut hotkeys to the target window to open the Import dialog.

Use Au3Info to detect the controlID of the "File name:" input control and the "Open" button. Then use ControlSetText() to set the filenames to open and finally ControlClick() on the open button.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

It really depends what you want to do. There are many ways to select files, but I would chose how based on what I was going to do next.

Perhaps you should explain a little more and post some code.

I do the same way as given in those pictures above.

The code for it is given below. Data is getting updated in those excel/ascii files and i import it into the charting software. Since i do it quite frequently (once every 30 secs), it wud be good, if there are any quicker ways to do it. The code given below may look primitive, but it is how i do it :graduated:

WinActivate("Charting software","-")   ;Activate charting software 
Sleep(200)
Send("!{F}")   ;Select File menu
Sleep(200)
Send("i")   ;Select Ascii import submenu
WinWaitActive("Open","Folder")   ;wait for Open dialog
WinMove("Open","FolderView",345,-590)
Mouseclick("left",495,-330,1,1)   ;Select POINTER folder
MouseClick("left",865,-255,1,1)   ;Click OK
Sleep(200)
MouseClick("right",520,-450,1,1)   ;Right click in open space
MouseMove(590,-415)   ;Mouse hover on Arrange icons
Sleep(200)
Send("t")   ;Select Arrange icons as per type
MouseClickDrag("left",842,-436,882,-345,1)   ;Left Click and drag mouse on 6 .csv files
MouseClick("left",865,-255,1,1)   ;Click OK
Edited by nbala75

Share this post


Link to post
Share on other sites

Use ControlSend() to send Shortcut hotkeys to the target window to open the Import dialog.

Use Au3Info to detect the controlID of the "File name:" input control and the "Open" button. Then use ControlSetText() to set the filenames to open and finally ControlClick() on the open button.

Hi Kafoo

I am not able to find ControlIDs for most of the items/fields. I tried using WinMenuSelectItem, even that doesnt work. How to go abt it?

I tried using class or classnameNN name...but it doesnt work

Posted Image :graduated:

Share this post


Link to post
Share on other sites

Hu, looks like the program is using some custom control types, at least for the menu itself. Stick to your code up to and including "WinWaitActive("Open","Folder")", try to find controlIDs for the "Open" dialog itself, that seems to be pretty standard, at least from the looks, then only automate that part with controlsend() and controlclick(). Hint, you can add a list of full qualified paths to the input control ('"c:\test\text1.txt" "c:\test\text2.txt" "c:\test\text3.txt"') and don't need to browse for the correct folder.

Share this post


Link to post
Share on other sites

Hu, looks like the program is using some custom control types, at least for the menu itself. Stick to your code up to and including "WinWaitActive("Open","Folder")", try to find controlIDs for the "Open" dialog itself, that seems to be pretty standard, at least from the looks, then only automate that part with controlsend() and controlclick(). Hint, you can add a list of full qualified paths to the input control ('"c:\test\text1.txt" "c:\test\text2.txt" "c:\test\text3.txt"') and don't need to browse for the correct folder.

thanx for explaining in very simple terms...i got it

except that i do not know how to select (controlsend) mutliple file names in the "Open Dialog/File name" edit field

I tried sending it with doublequotes(") OR comma(,) OR quotes(') OR Space( ) ...but nothing works

after wandering thru net :graduated: , i have come back to u Mr Kafu...plz help me out

Posted Image

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

You nearly got it :(, enclose all filenames with single quotes and the single filenames with double quotes. The single quote is for autoit to recognize a string, the double quote for the open dialog to separate the single files.

$sFiles = '"c:\test\text1.txt" "c:\test\text2.txt" "c:\test\text3.txt"'

Edit: Btw, I'm currently tinkering on a similar program :graduated:, only that I gave up the intraday approach and now I'm working on a daily basis :D...

Edit2: Or if you need to concatenate single strings, you'll have to consider that quotes are escaped by quotes (sounds silly, but it's a fact).

$sFile1 = "c:\test\text1.txt"
$sFile2 = "c:\test\text2.txt"
$sFiles = '"' & $sFile1 & '" "' & $sFile2 & '"'
MsgBox(0,"",$sFiles)
$sFiles = """" & $sFile1 & """ """ & $sFile2 & """"
MsgBox(0,"",$sFiles)
Edited by KaFu

Share this post


Link to post
Share on other sites

$sFile1 = "c:\test\text1.txt"
$sFile2 = "c:\test\text2.txt"
$sFiles = '"' & $sFile1 & '" "' & $sFile2 & '"'
MsgBox(0,"",$sFiles)
$sFiles = """" & $sFile1 & """ """ & $sFile2 & """"
MsgBox(0,"",$sFiles)

Isn't that kind of a hard way to use doublequotes? If you want to use double quotes in the string you can put that directly between single quotes, just like the other way around... The following works just as well:

$sFile1 = '"c:\test\text1.txt"'
$sFile2 = '"c:\test\text2.txt"'
$sFiles = $sFile1 & " " & $sFile2
MsgBox(0,"",$sFiles)

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

$sFile1 = 'c:\test\text1.txt'
$sFile2 = 'c:\test\text2.txt'
$sFiles = _Quote($sFile1) & " " & _Quote($sFile2)
MsgBox(0,"",$sFiles)
Func _Quote($s)
    Return '"' & $s & '"'
EndFunc

I guess there are some dozened more ways to do it, as long as the resulting syntax is correct :graduated:...

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Sorry to come back to u Kafu...it doesnt work and i cud not find a solution

As u had suggested in one of ur posts, that i can just give the correct path, without worrying to open the correct folder, i just gave like that enclosing the path within double quotes. The OPEN dialog doesnt give any error NOR it updates the quotes.

I tried searching thru folder options, control panel etc, but, cud not get what is wrong

just have a look at the pictures

when given like this, there is no error msg and no updation happens...

Posted Image

When multiple files selected inside the relevant Folder, then it is getting updated :graduated:

Posted Image

Edited by nbala75

Share this post


Link to post
Share on other sites

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