Jump to content
Sign in to follow this  
HimanshuG

LOF (Length Of File)

Recommended Posts

HimanshuG

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:

Share this post


Link to post
Share on other sites
UEZ

Look in the help file for _FileCountLines

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
hannes08

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]

Share this post


Link to post
Share on other sites
ProgAndy

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

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.