FIFO queue

Good day,
we're having a door lock project using RFID which uses SD Card where we can store the logs or data.

Our problem is :
We have logs.csv where it contains maximum lists of 50 the idea here is first in first out (FIFO). so, here it goes; when someone scanned their accessed card then it will insert/save to logs.csv.
when the data reaches to the maximum number of 50 then that data will be deleted when there is new data save (my main point here is , last data will be replaced of the new data).

Please respect . Thank you God bless.

As far as I know you can't do this directly. So you have to make a shadow copy

  1. Make a new file
  2. Copy the content from line 2 and up
  3. add new entry
  4. delete old file
  5. rename new file

Or, now I think of it

  1. Copy line 2 to line 1
  2. Copy line 3 to line 1
  3. Write new entry to line 50

If your records are fixed length you can position the file to the record to be overwritten and overwrite it.

Read the current record index from EEPROM (or from a file).
Position the file to RECORD_SIZE * index.
Write the record.
Set the index to (index+1)%50
Write the index to EEPROM (or to a file)