src/WebFSEditor.cpp
// list all of the files, if ishtml=true, return html else json
list all of the files, if ishtml=true, return html else json
list all of the files if ishtml = true return html else json
String WebFSEditor::listFiles(bool ishtml) {
  _doLoop = false;
  xSemaphoreTake( xSPISemaphore, portMAX_DELAY );
  String returnText = "";
  Serial.println("Listing files stored on _fs");
  File root = _fs.open("/");
  File foundfile = root.openNextFile();
  if (ishtml) {
    returnText += "<table><tr><th align='left'>Name</th><th align='left'>Size</th><th></th><th></th></tr>";
  } else {
    returnText += "{ \"files\":[\n";
  }
  uint8_t i=0;
  while (foundfile) {
    if (ishtml) {
      returnText += "<tr align='left'><td>" + String(foundfile.name()) + "</td><td>" + humanReadableSize(foundfile.size()) + "</td>";
      returnText += "<td><button onclick=\"downloadDeleteButton(\'" + String(foundfile.name()) + "\', \'download\')\">Edit</button>";
      returnText += "<td><button class=danger onclick=\"downloadDeleteButton(\'" + String(foundfile.name()) + "\', \'delete\')\">Delete</button></tr>";
    } else {
      if (i>0) returnText += ",";
      returnText += "{\"name\":\"" + String(foundfile.name()) + "\", \"size\":" + foundfile.size() + "}\n";
    }
    i++;
    foundfile = root.openNextFile();
    yield();
  }
  if (ishtml) {
    returnText += "</table>";
  } else {
    returnText += "]}";
  }
  root.close();
  foundfile.close();
  _doLoop = true;
  return returnText;
}
String WebFSEditor :: listFiles ( bool ishtml ) { _doLoop = false ; xSemaphoreTake ( xSPISemaphore , portMAX_DELAY ) ; String returnText = " " ; Serial . println ( " " ) ; File root = _fs . open ( " " ) ; File foundfile = root . openNextFile ( ) ; if ( ishtml ) { returnText += " " ; } else { returnText += " \" \" \n " ; } uint8_t i = 0 ; while ( foundfile ) { if ( ishtml ) { returnText += " " + String ( foundfile . name ( ) ) + " " + humanReadableSize ( foundfile . size ( ) ) + " " ; returnText += " \" \' " + String ( foundfile . name ( ) ) + " \' \' \' \" " ; returnText += " \" \' " + String ( foundfile . name ( ) ) + " \' \' \' \" " ; } else { if ( i > 0 ) returnText += " " ; returnText += " \" \" \" " + String ( foundfile . name ( ) ) + " \" \" \" " + foundfile . size ( ) + " \n " ; } i ++ ; foundfile = root . openNextFile ( ) ; yield ( ) ; } if ( ishtml ) { returnText += " " ; } else { returnText += " " ; } root . close ( ) ; foundfile . close ( ) ; _doLoop = true ; return returnText ; }
list all of the files, if ishtml=true, return html else json
list all of the files if ishtml = true return html else json
//xSemaphoreGive( xSPISemaphore );