Jump to content

Read from text file, pause, read again


Recommended Posts

Howdy folks.

I am need of some help. I have been reading the help file, and looking through here. I have not quite found what I'm looking for.

what I am trying to do is read a the first line of a text file, have Autoit do something with the first line, then come back and get the second line, and repeat.

I have the open file, and read file line down (I think). What I can't figure out is how to make Autoit "do something", then come back and read the next line, and repeat this till its done. I have the filecountlines working.

; begin- count lines in file
#include <File.au3>
$txtfile="url.txt"
$lines = _FileCountLines($txtfile)
; MsgBox(64, "Lines", "There are " & $lines & " lines in your file.")
; end- file line count

; begin- increase filereadline by one
$x= 1
do
$file = FileOpen("url.txt", 0)
$Number = FileReadline($file, $x) 
; MsgBox(0, "Line "&$x, $Number)
clipput($Number)
$x +=1
Until $x=$lines
FileClose($file)
; end- done increase by 1

The above is just an example of the snippets of code I have tried. Like I said I think I have the read file, and count lines right, but how do you do "just one at a time"?

If I need to clarify anything please let me know, and please someone help with this. I am just starting to get good at using Autoit, but this is starting to IRK me.

Thanx for any replies.

Link to comment
Share on other sites

You're doing it wrong.

#include <File.au3>
$txtfile="url.txt"
$lines = _FileCountLines($txtfile)
; MsgBox(0x2000, "Lines", "There are " & $lines & " lines in your file.")
; end- file line count

;you only open the file once
$file = FileOpen($txtfile, 0)
If $file = -1 Then
    MsgBox (0x2000, "Error", "Failed to open file!")
    Exit
EndIf
$x = 1
While 1
    ;read one line from file
    $Number = FileReadline($file)
    ;exit loop if no more lines to process
    If @error Then ExitLoop
    ;put line processing code here
    MsgBox(0, "Line "&$x, $Number)
    clipput($Number)
    $x += 1
WEnd
FileClose($file)
Edited by omikron48
Link to comment
Share on other sites

@ omikron48

This is very close to what I need to do (A million thanks). I have some more questions for you.

What I am trying to do is:

Read line 1

paste line 1 into the address bar of a "web browser".

wait an hour.

read line 2

paste line 2 into the address bar of a "web browser".

wait an hour.

Read line 3

paste line 3 into the address bar of a "web browser".

wait an hour.

repeat till end of file.

Once I get the above to work right, I think I'll have this son of a b**** working.

Link to comment
Share on other sites

@ omikron48

This is very close to what I need to do (A million thanks). I have some more questions for you.

What I am trying to do is:

Read line 1

paste line 1 into the address bar of a "web browser".

wait an hour.

read line 2

paste line 2 into the address bar of a "web browser".

wait an hour.

Read line 3

paste line 3 into the address bar of a "web browser".

wait an hour.

repeat till end of file.

Once I get the above to work right, I think I'll have this son of a b**** working.

Global $Path = @DesktopDir & "\url.txt"

$hFileOpen = FileOpen($Path, 0)
$hFileRead = FileRead($hFileOpen)
$iTotalLines = StringSplit($hFileRead, Chr(10))

For $i = 1 To $iTotalLines[0]
    $sLineRead = FileReadLine($hFileOpen, $i)

    MsgBox(0, "", "Replace this msgbox with your code to paste it into the address bar." & @CRLF & _
                        @CRLF & "Current line: " & $i & @CRLF & "Current line read: " & $sLineRead)

    ;Sleep((1000 * 60) * 60) ; 1000ms * 60 = 1 min * 60 is 60 min
Next

FileClose($hFileOpen)

Something like that?

Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

@ AlmarM

You Sir are "The Man". Thanx a billion for your help. That works perfectly. I am glad I asked for help, as looking at your code, I would have never figured that out on my own.

I tweaked the "code" to see if it would work:

; Global $Path = @DesktopDir & "\url.txt"

$hFileOpen = FileOpen("url.txt", 0)
$hFileRead = FileRead($hFileOpen)
$iTotalLines = StringSplit($hFileRead, Chr(10))

For $i = 1 To $iTotalLines[0]
    $sLineRead = FileReadLine($hFileOpen, $i)

    ;MsgBox(0, "", "Replace this msgbox with your code to paste it into the address bar." & @CRLF & _
                        ;@CRLF & "Current line: " & $i & @CRLF & "Current line read: " & $sLineRead)
    clipput($sLineRead)
    Sleep(500)     ; (1000 * 60) * 60) ; 1000ms * 60 = 1 min * 60 is 60 min
Next

FileClose($hFileOpen)

With your orginal code (untouched by me) I was getting an error on line 15. I have no line 15 in the "url.txt" file.

Current line: 15

Current line read: is blank.

Its not a big deal as the script will be done by that line, I'm just curious why I'm getting that.

Link to comment
Share on other sites

With your orginal code (untouched by me) I was getting an error on line 15. I have no line 15 in the "url.txt" file.

Current line: 15

Current line read: is blank.

Its not a big deal as the script will be done by that line, I'm just curious why I'm getting that.

Mayby your url.txt looks like this?

Line1
Line2
Line3
...
Line14
<This is line 15, mayby there's just a enter or a space here?>
Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

@ AlmarM

You Sir are really good at this. If I could buy you a beer I would :blink:

Is there anyway to put "Solved" in the topic header?

Edit your first post with "Use Full Editor" and change topic title. ;) Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

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