djuseeq / Ch376msc

Arduino library for CH376 mass storage contoller
MIT License
77 stars 17 forks source link

programatical filename for write to, results in unreadable file #40

Closed petervanderwalt closed 3 years ago

petervanderwalt commented 3 years ago
  // Custom filenames causes issues opening file
  //String fileName = filename.substring(0, 8);
  //fileName = fileName += ".EXT";
  //flashDrive.setFileName(fileName.c_str());  // does not work 
  flashDrive.setFileName("TEST.TXT");   // works

Works fine! flashDrive.setFileName("TEST.TXT");

but if I try setting the filename dynamically:

  //String fileName = filename.substring(0, 8);
  //fileName = fileName += ".GCO";
  //flashDrive.setFileName(fileName.c_str());  // does not work 

File gets created, but cannot open it in Windows: opening the file from explorer:

image

petervanderwalt commented 3 years ago

You know how minutes after posting an issue it hits you right after looking at it for hours! Classic case here. Looking at the screenshot I just oploaded, I realized lowercase isnt 8.3 format. Threw in a toUpperCase on the string before converting it, and sorted!

String fileName = filename.substring(0, 8); fileName = fileName += ".GCO"; fileName.toUpperCase(); flashDrive.setFileName(fileName.c_str()); // does not work