I have a file stored in an sd card that has multiple records, each record is one line.
What i am trying to do is delete only one line in the middle of the file.
Is there a way to do that?
i am able to find the start and stop position of the line that i want to delete,
but i cannot delete the character, i do not want to overwrite them with space, just delete them
Any ideas?
So there is no "easy" way? it seems inefficient to copy the entire file, especially if it is a big one.
what do you mean by a deleted character?
i am thinking about overwriting the entire line with "-" for example, but that does not reduce the file size
(do you mean something like that?)
The SD card "knows" nothing about lines. It simply stores the characters you send it.
To delete a line, you first have to define what a line is (and there are many popular definitions), then copy the entire file leaving out the part you don't want.
jremington:
The SD card "knows" nothing about lines. It simply stores the characters you send it.
To delete a line, you first have to define what a line is (and there are many popular definitions), then copy the entire file leaving out the part you don't want.
The easiest algorithm to physically delete a single line from a file is:
copy the original file to a temporary file, without copying the deleted line
delete the original file
rename the temporary file name to the original file name
But don't forget to do proper error checking while doing each of the steps, otherwise you may end up in a completely empty file in the end!
A much faster and safer solution would be not to delete the line physically, but logically only. Just overwrite all the 'logically deleted' characters with a different character which is otherwise not used within the file, perhaps 0x1A. And when reading in the data, skip all the logically deleted characters.
Just overwrite all the 'logically deleted' characters with a different character which is otherwise not used within the file, perhaps 0x1A. And when reading in the data, skip all the logically deleted characters.
This would require some sort of block or direct record access. How do you know where those characters to be "logically deleted" are, within the file?
jremington:
This would require some sort of block or direct record access. How do you know where those characters to be "logically deleted" are, within the file?
It depends on how you access the file.
In case you do sequential access to the file only, you always start reading the file from the beginning. Line number depends on how many 0x0D characters you have read.
And in case you do random access to the file and are using fixed-lenght-recods (fixed length lines), record number and line number are identical.
jremington:
The SD card "knows" nothing about lines. It simply stores the characters you send it.
To delete a line, you first have to define what a line is (and there are many popular definitions), then copy the entire file leaving out the part you don't want.
As i mentioned on my 1st post i know where the start and end of my "line" is,
i am trying to avoid having to rewrite the entire file because it might be too big to do that.
I will probably replace the lines that i want to delete with a special character e.x."-"
end when i read the file again i will just skip those chars.
Thank you all