You need to read line by line, or character by character, to work out the number of lines.
A simpler way to do this in your circumstances may be to have a second file with the number of lines in the file. Every time you write a bunch of lines in the data file, you read the 'line' file, add the number you have just written and rewrite the value out to the line file.
Mmmhhh an extra file ,, adding a extra number , thats an idee, indeed. But it must also be suitable, when my software is completely resetted. All counters are resetted (only info in eeprom is still present). Writing every 5 min to an eeprom is not a good idee to me
reading line for line , than looks the best way. Or i have to save a counter in a file, and every time i have a new logging, i have to read the counter from the file and increase it ans save it back..
but there should be a pionter in a file , so every time it opens the file it knows where it was last time... i thought the
"file.position()" function should do that . without reading all the data in the file , it reads only the position
The file size before logging will be a probleem, when software has resetted. Then i do not know the size anymore
Reading the size of a file before you write to it and after you write to it is exactly the same process, It has nothing to do with the Arduino be reset or the software being reset (whatever that means).
Open the file for write. Read the position of the write cursor. Close the file. You know how big the file is. Open the file for write. Write some data. Read the position of the write cursor. Close the file Now, you know how big the file is after adding to it. The change in size is the number of characters added to the file.
The reset, could be generated, bY watchdog or powerfailer.
The arduino is restarting after that, so no values are known
If i open the file, it would be nice bY asking position, how many lines are written(lines do not have to samen size).
By reading, file.position() want info i get?
I want to know, after a quick scan, how many lines are written, so i get a overview how many lines/loggings are missed.
Not only if last logging was written
The arduino is restarting after that, so no values are known
Learn them. The size of the file is not affected by resetting the Arduino, unless you are failing to close the file correctly. Determining the size of a file before writing to it is trivial. Learning the size of the file after writing to it is equally trivial.
If i open the file, it would be nice bY asking position, how many lines are written(lines do not have to samen size).
If your records are not all the same length, then the size of the file is no indication of the number of records. You must then open the file, read and count each record, and close the file.
By reading, file.position() want info i get?
The location where you will read or write, depending on the mode of the file. A file opened for write has the write point positioned at the end of the file, so file.position will tell you the number of bytes in the file.
The location where you will read or write, depending on the mode of the file. A file opened for write has the write point positioned at the end of the file, so file.position will tell you the number of bytes in the file.
If the file is to be truncated (the only other option), that happens when the file is closed. So, position does tell you (correctly) the number of bytes in the file when it is (to be) closed.
But, yes, I should have made it clear that append and truncate have an impact on the value in position.
OK, so file.position() returns the bytes of the file at that position (read or write postions) so it is actually the size what is returned , not the position..
this function is than not usefull in my case,
by the way , some text was not written correctly on this post, my phone was correcting my line in a wrong text
sorry for that..
you mean O_APPEND - If set, the file offset shall be set to the end of the file prior to each write
i use for writing
logFile = SD.open(fullName, O_CREAT | O_APPEND | O_WRITE);.. but how can i use it for reading number of lines then?
i will check the size of the file before and after next saving in normal situation every 5 min(So i know a new line was saved)
And when the arduino has restarted for some reason , i will count line by line the file