diff --git a/Grbl_Esp32/commands.cpp b/Grbl_Esp32/commands.cpp index 1c7dff63..f1298477 100644 --- a/Grbl_Esp32/commands.cpp +++ b/Grbl_Esp32/commands.cpp @@ -881,6 +881,53 @@ bool COMMANDS::execute_internal_command (int cmd, String cmd_params, level_authe } break; + //Delete SD Card file / directory + //[ESP215]pwd= + 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] case 220: diff --git a/doc/Commands.txt b/doc/Commands.txt index c9705b30..2071a42b 100644 --- a/doc/Commands.txt +++ b/doc/Commands.txt @@ -85,6 +85,9 @@ Reply: 81 * Get SD Card Content [ESP210] pwd= +* Delete SD Card file / directory +[ESP215]pwd= + * Print SD file [ESP220] pwd=