TestGetName.ino 939 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "SdFat.h"
  2. SdFs sd;
  3. FsFile file;
  4. const char* name[] = {
  5. "SFN.TXT",
  6. "LongFilename.txt",
  7. #if USE_UTF8_LONG_NAMES
  8. u8"très élégant.txt",
  9. #endif // USE_UTF8_LONG_NAMES
  10. nullptr};
  11. char buf[32];
  12. void setup() {
  13. Serial.begin(9600);
  14. while (!Serial) {}
  15. Serial.println("Type any character to begin");
  16. while (!Serial.available()) {}
  17. if (!sd.begin(SS)) {
  18. sd.initErrorHalt();
  19. }
  20. for (uint8_t i = 0; name[i]; i++) {
  21. if (!file.open(name[i], O_CREAT |O_RDWR)) {
  22. sd.errorHalt("open");
  23. }
  24. size_t len = strlen(name[i]);
  25. size_t rtn = file.getName(buf, len);
  26. if (rtn != 0) {
  27. Serial.println("fail len");
  28. }
  29. rtn = file.getName(buf, len + 1);
  30. if (rtn != len) {
  31. Serial.println("fail len + 1");
  32. }
  33. Serial.print(rtn);
  34. Serial.print(' ');
  35. Serial.println(buf);
  36. if (!file.remove()) {
  37. sd.errorHalt("remove");
  38. }
  39. }
  40. Serial.println("Done");
  41. }
  42. void loop() {}