mirror of
https://github.com/bdring/Grbl_Esp32.git
synced 2025-08-18 20:31:35 +02:00
add ESP command to delete SD card file / directory
This commit is contained in:
@@ -881,6 +881,53 @@ bool COMMANDS::execute_internal_command (int cmd, String cmd_params, level_authe
|
||||
}
|
||||
break;
|
||||
|
||||
//Delete SD Card file / directory
|
||||
//[ESP215]<file/dir name>pwd=<user/admin password>
|
||||
case 215:
|
||||
{
|
||||
if (!espresponse) return false;
|
||||
#ifdef ENABLE_AUTHENTICATION
|
||||
if (auth_type == LEVEL_GUEST) {
|
||||
espresponse->println ("Error: Wrong authentication!");
|
||||
return false;
|
||||
|
||||
}
|
||||
#endif
|
||||
parameter = get_param (cmd_params, "", true);
|
||||
if (parameter.length() != 0) {
|
||||
int8_t state = get_sd_state(true);
|
||||
parameter.trim();
|
||||
if (parameter[0] != '/'){
|
||||
parameter = "/" + parameter;
|
||||
}
|
||||
if (state == SDCARD_IDLE) {
|
||||
File file2del = SD.open(parameter.c_str());
|
||||
if (file2del) {
|
||||
if (file2del.isDirectory()) {
|
||||
if (!SD.rmdir((char *)parameter.c_str())) {
|
||||
espresponse->println ("Error: Cannot delete directory! Is directory empty?");
|
||||
} else {
|
||||
espresponse->println ("Directory deleted.");
|
||||
}
|
||||
} else {
|
||||
if (!SD.remove((char *)parameter.c_str())) {
|
||||
espresponse->println ("Error: Cannot delete file!");
|
||||
} else {
|
||||
espresponse->println ("File deleted.");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
espresponse->println ("Error: Cannot stat file!");
|
||||
}
|
||||
file2del.close();
|
||||
} else {
|
||||
espresponse->println ((state == SDCARD_NOT_PRESENT) ? "No SD card" : "Busy");
|
||||
}
|
||||
} else {
|
||||
espresponse->println ("Error: Missing file name!");
|
||||
}
|
||||
}
|
||||
break;
|
||||
//print SD file
|
||||
//[ESP220]<filename>
|
||||
case 220:
|
||||
|
@@ -85,6 +85,9 @@ Reply: 81
|
||||
* Get SD Card Content
|
||||
[ESP210] pwd=<user/admin password>
|
||||
|
||||
* Delete SD Card file / directory
|
||||
[ESP215]<file/dir name>pwd=<user/admin password>
|
||||
|
||||
* Print SD file
|
||||
[ESP220] <Filename> pwd=<user/admin password>
|
||||
|
||||
|
Reference in New Issue
Block a user