Jump to content

Possible to FileReadLine backwards?


Recommended Posts

Hi everyone. I have a question about the FileReadLine function. Do you know if it is possible to read a text file from the bottom up instead of from the top down? I am writing a backup program and want to be able to make the program delete the oldest backup files. I have all of the names of my backup files created in a cmd window and sent to a text file. A few people told me that it was possible in older versions of AutoIt, but have no idea if it's possible with v3.

Link to comment
Share on other sites

HI,

is that really neccessary? You could use _FileReadToArray() and then take Ubound -1 , -2 and so on.

This way of course, you read the whole file. (Performance if hufe file :-( )

So long,

Mega

Edited by th.meger

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

#include <File.au3>

FileReadLine ( filehandle or "filename" , _FileCountLines(filehandle or "filename") - $number_of_lines_counting_from_bottom )

Hi,

_FileCountLines(filehandle or "filename") works only with path not with filehandle!

I have to test what is faster. Array, or FCL :D

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

  • Moderators

This is like _FileReadToArray(), but without the need to #include <file.au3>

$FilePath = 'Path to file here'
$FileRead = FileRead($FilePath, FileGetSize($FilePath))
$CreateArray = StringSplit($FileRead, @CR)
For $iCount = UBound($CreateArray) - 1 To 1 Step - 1;Start reading backwards
    ConsoleWrite($CreateArray[$iCount] & @LF)
Next

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I would look for something called a "tail utility". You'll find several commandline equivalents of the original Unix utility via Google.

Then you can just call it from your au3 script to produce the summarised logfile.

HTH

:D

Link to comment
Share on other sites

Hi,

_FileCountLines(filehandle or "filename") works only with path not with filehandle!

I have to test what is faster. Array, or FCL :D

So long,

Mega

Hi, you would only have to call it once;

$FileCountLines=FileCountLines( "filename")

$number_of_lines_counting_from_bottom=0

while 1

FileReadLine ( filehandle or "filename" , $FileCountLines- $number_of_lines_counting_from_bottom )

if @error then exitloop

$number_of_lines_counting_from_bottom+=1

wend

etc - would it work?; how quick?

I'd be interested in you timing results; not with Arrays for large files. though!?

[Even "tail.exe" in microsoft would neeed number of lines first, I think.]

Randall

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