Pages: [1]   Go Down
Author Topic: delete the text into the file  (Read 593 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 122
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


hello, there are any way to delete the text into a file on the sd card without you need remove or delete the file.

thanks
Logged

SE USA
Offline Offline
Faraday Member
**
Karma: 41
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

read the section in memory, change it, and save it back

which lib are you using, it seems kind of complicated with SDFATlib, might not be possible with the standard library included, dont know I never use it
Logged


Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 614
Posts: 49386
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
hello, there are any way to delete the text into a file on the sd card without you need remove or delete the file.
Open the file for write, in replace mode (not the default append mode). Close the file without actually writing anything.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you tell me how the 'replace' mode is implemented please?  I've been wrestling with trying to stop appending data to the file for two days, now and about to start looking for a tall building to jump off.
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 614
Posts: 49386
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is from SdFile.cpp:
Code:
* O_READ - Open for reading.
 *
 * O_RDONLY - Same as O_READ.
 *
 * O_WRITE - Open for writing.
 *
 * O_WRONLY - Same as O_WRITE.
 *
 * O_RDWR - Open for reading and writing.
 *
 * O_APPEND - If set, the file offset shall be set to the end of the
 * file prior to each write.
 *
 * O_CREAT - If the file exists, this flag has no effect except as noted
 * under O_EXCL below. Otherwise, the file shall be created
 *
 * O_EXCL - If O_CREAT and O_EXCL are set, open() shall fail if the file exists.
 *
 * O_SYNC - Call sync() after each write.  This flag should not be used with
 * write(uint8_t), write_P(PGM_P), writeln_P(PGM_P), or the Arduino Print class.
 * These functions do character at a time writes so sync() will be called
 * after each byte.
 *
 * O_TRUNC - If the file exists and is a regular file, and the file is
 * successfully opened and is not read only, its length shall be truncated to 0.

Each of the values can be OR'd together to open the file exactly the way that you want. The way to open the file is the 2nd argument to the open() method. To open a file for writing, creating it if doesn't exist, and deleting any data in the file if it does, use O_WRITE | O_CREAT | O_TRUNC.
Logged

Pages: [1]   Go Up
Jump to: