Jump to content

Questions about working with text files...


 Share

Recommended Posts

Opening and reading files is easy enough so far, but what I want to do is work with the latest data, in as close as I can get to real time.

Here's what I'm trying to do:

Read line from file --> determine which (if any) substring exists in the line --> preform action based on substring ---> repeat

Here's the issues I'm having:

- Determining where the starting point (aka end of the file is) when the script begins. For the life of me, I can't find an easy way to determine the length of a file in lines with AutoIt.

-Speed. It's a factor. The larger the file, the longer it takes to get the data at the end of the file. I can work at minimizing the length of the file to begin with, but what's the most efficient way to handle the process?

I've poked around but can't find anything quite on this subject. the closest I've found is the EQ2 bot that goes through the log file... but wipes it clean every cycle.

Link to comment
Share on other sites

$sFilePath = "somefile.txt"
Do
    Dim $aArray = ""
    _FileReadToArray($sFilePath, $aArray)
    $EndOfFile = $aArray[0];number of lines in file
    $Line = $aArray[$EndOfFile];Read line from array
    If StringInStr($Line, "some string") = 0 Then;determine which (if any) substring exists in the line
        ;perform action based on substring... if it's not found
    Else
        ;perform action based on substring... if it's found
    EndIf
Until ?????;repeat --- conditional...

The "Until ?????" needs to be defined. Without any code... I don't know the conditions that the loop needs.

Right now, this will loop until you terminate the script... obviously.

This is untested.

Edited by The Ape
Link to comment
Share on other sites

Opening and reading files is easy enough so far, but what I want to do is work with the latest data, in as close as I can get to real time.

Here's what I'm trying to do:

Read line from file --> determine which (if any) substring exists in the line --> preform action based on substring ---> repeat

Here's the issues I'm having:

- Determining where the starting point (aka end of the file is) when the script begins. For the life of me, I can't find an easy way to determine the length of a file in lines with AutoIt.

-Speed. It's a factor. The larger the file, the longer it takes to get the data at the end of the file. I can work at minimizing the length of the file to begin with, but what's the most efficient way to handle the process?

I've poked around but can't find anything quite on this subject. the closest I've found is the EQ2 bot that goes through the log file... but wipes it clean every cycle.

Hi,

Or , if you don't want to have to install or register anything, try the UDFs and examples in link in my signature to "TailRW"; reads and writes to lines at the end of a file, defined by you.

Best, Randall

Link to comment
Share on other sites

Thanks for the guidance.

I've got the basic setup working for me now, using The Ape's code.

I'll look at the other, faster options in the future, for now I can use this to iron out my system.

Just for anyone refering to this thread for similar information, there's one problem with the Code as written.

If StringInStr($EndOfFile, "some string")

should be

If StringInStr($Line, "some string")
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...