How to log only 10000 last values on sd card?

I made a temp sensor with sd card. I want to log last 1000 or 100000 last value so file size is under SDs memory.
How to delete the first row if logs are more than 100000 and add the next value at the end of the file?

Use multiple files in rotation, each file containing (say) 1000 values. When a file reaches it designated size close it and open a new one. If there is not enough space for the new file then delete the oldest and try again.

dpiralis:
I want to log last 1000 or 100000 last value so file size is under SDs memory.

Once you have made up your mind how many records you want to store, you might first check to see how big the card is, then give some thought about how many records will fit on it, and over what period of time.

Ring buffer.

Format your values so that they are all the same size, and keep a "next record to update" value somewhere - perhaps in a different file. Use seek() to overwrite the record at the 'next' position.

The records will be out of order, but not severely, and whatever you read them into will need to be able to deal with it.

stowite:
f there is not enough space for the new file then delete the oldest and try again.

How can I check free memory?

There is a way to check free memory, but I do not believe that this is what you really want to do. I think that you actually want to check how much space is available on the SD card. How you do that would depend upon what library you are using.

Where did you find an SD card with so little space on it that 10,000 measurements fills it up? I think you are underestimating how many samples you can store by a huge factor.

Like - seriously, the smallest I can find for sale is 2GB...

Temp logging should work for 5+ years so memmory will be a problem if there is not a limit. I want to keep only last (say) 100000 values.

I think I will use multiple files in rotation, and I will use onother file for "pointer" so after restart it will log on the last file. Files size will be pre calculated and it will never go out of memory.

dpiralis:
I think I will use multiple files in rotation, and I will use onother file for "pointer" so after restart it will log on the last file. Files size will be pre calculated and it will never go out of memory.

Well, I guess you find that easier to do than reading replies #2 andf #6.