Jump to content

LOF (Length Of File)


Recommended Posts

I am new to AutoIt and would like to know if there is any function which can return the number of lines in a file. I intend to go through a file and do something for each line of code as this of course requires a loop I want to make sure that the program only goes through the file till the end. If there is a way to find out if the file has ended it will also do.

Himanshu Goel :mellow:

Link to comment
Share on other sites

Well, technically _FileCountLines loops through the whole file, if you intend to use the file late on, you could use _FileReadToArray(), then you'll have both: The number of read lines in array element 0, and the contents of the file from array element 1 onward. :mellow:

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
Link to comment
Share on other sites

If you don't want to have all lines in memory, you'll have to use a loop that stops when no more lines are available:

$hFile = FileOpen("myfile.txt")
$linecount = 0
$line = FileReadLine($hFile)
while not @error
   $linecount += 1
   ... do something with $line
   $line = FileReadLine($hFile)
wend
FileClose($hFile)
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

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