Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Me-no-dev
#50732 You know what? When I read that I remember seeing recently in my SD sketches the following piece of code:
Code: Select allbool SD_exists(String path){
  bool exists = false;
  sd::File test = SD.open(path);
  if(test){
    test.close();
    exists = true;
  }
  return exists;
}


But in the same sketches I do use remove to delete the files
Code: Select allSD.remove((char *)path.c_str());


I guess I'll hook up mu SD and see what will happen
User avatar
By daveb1014
#50851 Thanks Me-no-dev, it looks like that was it.

This fails with a memory dump:
Code: Select allconst char* myFile = "file.txt";
...
SD.remove(myFile);


But this works as expected, and removes the file:
Code: Select allconst char* myFile = "file.txt";
...
SD.remove((char*)myFile);


eg. I assume by using a type of const char* instead of char*, I need to cast back to a char*

The same with SD.exists() - had to include a cast to char* and then it worked.

My fault (I'm definitely NOT a professional C programmer!) thanks for helping me discover my error.
User avatar
By martinayotte
#50861 This behavior is really strange !
I've never seen cases where giving a "const char *" instead of "char *" would cause a crash.
@me-no-dev, anyway, I suggest that SD.remove() and SD.exist() should use "const char *" to be consistent with other SD functions as well as FS functions.