Arduino SD Card Library: How to delete a line of data inside the file and remove

Hello everyone! I am not a newbie but an intermediate microprocessor programmer and aim to at least master some of the codes, specifically in Arduino. Here is my question regarding the subject:

How can I delete a line of data inside the file, display the data on the LCD I2C, and then delete it after a button is pressed? Another data will redo the loop until all the data inside the file is empty, but the file still remains.

Since we can print data inside the file using myFile.println(" "), I believe we can also remove data.

This is the example file:
games

File name: games.txt
data:
Basketball
Volleyball
Soccer
Baseball
Softball
Football
Sepak Takraw

Thank you so much.

The only way to delete a line from an SD file is to copy the file to another, except for the line in question, delete the original file and rename the output file (if desired).

1 Like

How about there are hundreds and thousands of data lines in a single file?

The number of lines is irrelevant.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.