Jump to content

Better way to select file(s) ?


nbala75
 Share

Recommended Posts

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.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

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

Link to comment
Share on other sites

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

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

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

Link to comment
Share on other sites

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

Link to comment
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:...

Link to comment
Share on other sites

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
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...