mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-19 13:54:23 +01:00
Adding SD.remove(file) and another example.
This commit is contained in:
parent
5af5619df4
commit
6f0ea10600
@ -294,10 +294,9 @@ boolean callback_openPath(SdFile& parentDir, char *filePathComponent,
|
||||
|
||||
*/
|
||||
if (isLastComponent) {
|
||||
SDClass *p_MemoryCard = static_cast<SDClass*>(object);
|
||||
p_MemoryCard->file.open(parentDir, filePathComponent,
|
||||
p_MemoryCard->fileOpenMode);
|
||||
p_MemoryCard->c = -1;
|
||||
SDClass *p_SD = static_cast<SDClass*>(object);
|
||||
p_SD->file.open(parentDir, filePathComponent, p_SD->fileOpenMode);
|
||||
p_SD->c = -1;
|
||||
// TODO: Return file open result?
|
||||
return false;
|
||||
}
|
||||
@ -305,6 +304,16 @@ boolean callback_openPath(SdFile& parentDir, char *filePathComponent,
|
||||
}
|
||||
|
||||
|
||||
boolean callback_remove(SdFile& parentDir, char *filePathComponent,
|
||||
boolean isLastComponent, void *object) {
|
||||
if (isLastComponent) {
|
||||
SdFile::remove(parentDir, filePathComponent);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Implementation of class used to create `SDCard` object. */
|
||||
|
||||
@ -415,4 +424,8 @@ boolean SDClass::mkdir(char *filepath) {
|
||||
return walkPath(filepath, root, callback_makeDirPath);
|
||||
}
|
||||
|
||||
void SDClass::remove(char *filepath) {
|
||||
walkPath(filepath, root, callback_remove);
|
||||
}
|
||||
|
||||
SDClass SD;
|
@ -60,6 +60,9 @@ public:
|
||||
// Create the requested directory heirarchy--if intermediate directories
|
||||
// do not exist they will be created.
|
||||
boolean mkdir(char *filepath);
|
||||
|
||||
// Delete the file.
|
||||
void remove(char *filepath);
|
||||
|
||||
private:
|
||||
SdFile file;
|
||||
|
33
libraries/SD/examples/Files/Files.pde
Normal file
33
libraries/SD/examples/Files/Files.pde
Normal file
@ -0,0 +1,33 @@
|
||||
#include <SD.h>
|
||||
|
||||
File f;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
Serial.print("Initializing SD card...");
|
||||
SD.begin();
|
||||
Serial.println("done.");
|
||||
|
||||
if (SD.exists("example.txt")) Serial.println("example.txt exists.");
|
||||
else Serial.println("example.txt doesn't exist.");
|
||||
|
||||
Serial.println("Creating example.txt...");
|
||||
f = SD.open("example.txt", true);
|
||||
f.close();
|
||||
|
||||
if (SD.exists("example.txt")) Serial.println("example.txt exists.");
|
||||
else Serial.println("example.txt doesn't exist.");
|
||||
|
||||
Serial.println("Removing example.txt...");
|
||||
SD.remove("example.txt");
|
||||
|
||||
if (SD.exists("example.txt")) Serial.println("example.txt exists.");
|
||||
else Serial.println("example.txt doesn't exist.");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user