Author Topic: How to get a file's line count?  (Read 2158 times)

I would like to know if there is an efficient way of getting a file's line count without looping through the file.




Let me explain what im trying to do, i want to make a loading bar for how much of the file has been read, how would i get the % of the file read (or how would i do the loading bar if im not able to get the %)?
« Last Edit: July 05, 2013, 06:34:46 PM by Wrapperup »

Let me explain what im trying to do, i want to make a loading bar for how much of the file has been read, how would i get the % of the file read (or how would i do the loading bar if im not able to get the %)?
You can't
Unless you are writing the file yourself, that's also how the save file upload has a progress bar
It writes the line count somewhere in the header and reads it at the beginning, then simply counts

You can't
Unless you are writing the file yourself, that's also how the save file upload has a progress bar
It writes the line count somewhere in the header and reads it at the beginning, then simply counts

never mind then, thanks anyway.

EDIT: Unlocked incase anyone has a solution.
« Last Edit: July 06, 2013, 09:57:19 AM by Wrapperup »

impossible
wrong
You can't
WRONG

getFieldCount(getFileContents("file.path"));

As long as your file doesn't have tabs in it this will work just fine.

wrongWRONG

getFieldCount(getFileContents("file.path"));

As long as your file doesn't have tabs in it this will work just fine.
getFileContents is a function from RTB; make sure you copy the function's code into your own add-on.

IIRC there's a default function for this that starts with getFile.. I'm probably wrong though.

getFileContents is a function from RTB; make sure you copy the function's code into your own add-on.
Oh, I thought that was a default function.

Well then, as long as your client/server has rtb it'll work...

Wouldn't getRecordCount work?

wrongWRONG

getFieldCount(getFileContents("file.path"));

As long as your file doesn't have tabs in it this will work just fine.
What do you think a function called getFileContents does?
RIGHT, IT READS THE WHOLE FILE

Also, you probably mean getLineCount not getFieldCount

What do you think a function called getFileContents does?
RIGHT, IT READS THE WHOLE FILE
I'd like to see you come up with something better.

Wouldn't getRecordCount work?
And what would you use that function on?

I'd like to see you come up with something better.
So you think reading the file 2 times is a good idea? Congrats, you won the first price.
What he wants is to know the ammount of lines before reading it so he can have a progress bar - and the only way to do that is to store the ammount of lines at the top of the file.