diff --git a/src/activities/home/FileBrowserActivity.cpp b/src/activities/home/FileBrowserActivity.cpp index 3ea626e2..870e93b6 100644 --- a/src/activities/home/FileBrowserActivity.cpp +++ b/src/activities/home/FileBrowserActivity.cpp @@ -139,17 +139,20 @@ void FileBrowserActivity::loop() { return; } - if (mode == Mode::Books && mappedInput.getHeldTime() >= GO_HOME_MS && !isDirectory) { - // --- LONG PRESS ACTION: DELETE FILE --- + if (mode == Mode::Books && mappedInput.getHeldTime() >= GO_HOME_MS) { + // --- LONG PRESS ACTION: DELETE FILE OR DIRECTORY --- std::string cleanBasePath = basepath; if (cleanBasePath.back() != '/') cleanBasePath += "/"; const std::string fullPath = cleanBasePath + entry; - auto handler = [this, fullPath](const ActivityResult& res) { + auto handler = [this, fullPath, isDirectory](const ActivityResult& res) { if (!res.isCancelled) { LOG_DBG("FileBrowser", "Attempting to delete: %s", fullPath.c_str()); - clearFileMetadata(fullPath); - if (Storage.remove(fullPath.c_str())) { + if (!isDirectory) { + clearFileMetadata(fullPath); + } + const bool deleted = isDirectory ? Storage.removeDir(fullPath.c_str()) : Storage.remove(fullPath.c_str()); + if (deleted) { LOG_DBG("FileBrowser", "Deleted successfully"); loadFiles(); if (files.empty()) { @@ -161,7 +164,7 @@ void FileBrowserActivity::loop() { requestUpdate(true); } else { - LOG_ERR("FileBrowser", "Failed to delete file: %s", fullPath.c_str()); + LOG_ERR("FileBrowser", "Failed to delete: %s", fullPath.c_str()); } } else { LOG_DBG("FileBrowser", "Delete cancelled by user");