mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-16 11:21:18 +03:00
Adding SD.rmdir(). Returning success / failure from SD functions.
This commit is contained in:
@ -182,6 +182,10 @@ boolean walkPath(char *filepath, SdFile& parentDir,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!moreComponents) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
boolean exists = (*p_child).open(*p_parent, buffer, O_RDONLY);
|
boolean exists = (*p_child).open(*p_parent, buffer, O_RDONLY);
|
||||||
|
|
||||||
// If it's one we've created then we
|
// If it's one we've created then we
|
||||||
@ -204,14 +208,11 @@ boolean walkPath(char *filepath, SdFile& parentDir,
|
|||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!moreComponents) {
|
|
||||||
// TODO: Check if this check should be earlier.
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (p_parent != &parentDir) {
|
||||||
(*p_parent).close(); // TODO: Return/ handle different?
|
(*p_parent).close(); // TODO: Return/ handle different?
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -307,8 +308,17 @@ boolean callback_openPath(SdFile& parentDir, char *filePathComponent,
|
|||||||
boolean callback_remove(SdFile& parentDir, char *filePathComponent,
|
boolean callback_remove(SdFile& parentDir, char *filePathComponent,
|
||||||
boolean isLastComponent, void *object) {
|
boolean isLastComponent, void *object) {
|
||||||
if (isLastComponent) {
|
if (isLastComponent) {
|
||||||
SdFile::remove(parentDir, filePathComponent);
|
return SdFile::remove(parentDir, filePathComponent);
|
||||||
return false;
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean callback_rmdir(SdFile& parentDir, char *filePathComponent,
|
||||||
|
boolean isLastComponent, void *object) {
|
||||||
|
if (isLastComponent) {
|
||||||
|
SdFile f;
|
||||||
|
if (!f.open(parentDir, filePathComponent, O_READ)) return false;
|
||||||
|
return f.rmDir();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -420,8 +430,19 @@ boolean SDClass::mkdir(char *filepath) {
|
|||||||
return walkPath(filepath, root, callback_makeDirPath);
|
return walkPath(filepath, root, callback_makeDirPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDClass::remove(char *filepath) {
|
boolean SDClass::rmdir(char *filepath) {
|
||||||
walkPath(filepath, root, callback_remove);
|
/*
|
||||||
|
|
||||||
|
Makes a single directory or a heirarchy of directories.
|
||||||
|
|
||||||
|
A rough equivalent to `mkdir -p`.
|
||||||
|
|
||||||
|
*/
|
||||||
|
return walkPath(filepath, root, callback_rmdir);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean SDClass::remove(char *filepath) {
|
||||||
|
return walkPath(filepath, root, callback_remove);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDClass SD;
|
SDClass SD;
|
@ -59,7 +59,9 @@ public:
|
|||||||
boolean mkdir(char *filepath);
|
boolean mkdir(char *filepath);
|
||||||
|
|
||||||
// Delete the file.
|
// Delete the file.
|
||||||
void remove(char *filepath);
|
boolean remove(char *filepath);
|
||||||
|
|
||||||
|
boolean rmdir(char *filepath);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SdFile file;
|
SdFile file;
|
||||||
|
Reference in New Issue
Block a user