Jump to content

Why so complicated? Typical batch: Open, send keys, end, again


Eng
 Share

Recommended Posts

Hi dear community,

Before starting this topic, I've searched on manuals, examples and forums but I couldn't find. In my opinion this should be a fundamental request. For my part all newbies are curious about this.

Batch processes are big deal. Could you explain simply by giving an example? How can we do the following loop:

  1. List files on specific directory (maybe by extension, for example *.txt)
  2. Take the first file, open it with an external application.
  3. Send keystrokes or anything... on the external application.
  4. End the process of the external application.
  5. Take the 2nd file, and open...

I really appreciate any help you can provide.

Link to comment
Share on other sites

  • Developers

Open the Helpfile and search for:

  1. FileFindFirstFile / FileFindNextFile /  _FileListToArray
  2. Run / ShellExecute
  3. Send() / ControlSend()
  4. ProcessClose()
  5. For ... Next

Can't be that hard ;)

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Thanks for replying, sir. Do not be annoyed with me. Without an example I do not understand. So I tried changing the example in the help file. The end part is wrong, of course. :sweating:

#include <MsgBoxConstants.au3>

Example()

Func Example()
    Local $hSearch = FileFindFirstFile("*.txt")

    ; Check if the search was successful, if not display a message and return False.
    If $hSearch = -1 Then
        MsgBox($MB_SYSTEMMODAL, "", "Error: No files/directories matched the search pattern.")
        Return False
    EndIf

    ; Assign a Local variable the empty string which will contain the files names found.
    Local $sFileName = "", $iResult = 0

    While 1
        $sFileName = FileFindNextFile($hSearch)
        ; If there is no more file matching the search.
        If @error Then ExitLoop

        ; Do it
        ShellExecute ($sFileName)
        Sleep(2000)
        Send("^k")
        Sleep(1000)
        Send("{ENTER}")
        Sleep(1000)
        Send("{ENTER}")
        Send("!{F4}")
        Sleep(2000)
        ExitLoop;
    WEnd

    ; Close the search handle.
    FileClose($hSearch)
EndFunc   ;==>Example

 

Link to comment
Share on other sites

  • Developers

I assume it only does one file?  That last ExitLoop looks wrong and should be removed.
Else describe if you still have a question or not. ;) 

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers
21 minutes ago, Eng said:

Wow thank you! It works. By the way your brain works like a compiler.

They didn't tell you on your way in?  ...  I am a robot. ;)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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