I'm using the SdFat.h library on a STM32 and I can successfully create a file in the root directory using SD.open("test.txt", FILE_WRITE); but my code fails to create SD.open("DATA/data_test.txt", FILE_WRITE); in a directory. Here's the piece of code that successfully creates a file in the root:
String final_book_name = upload_book_name + ".txt";
if (SD.exists(final_book_name.c_str())) {
SD.remove(final_book_name.c_str());
}
tft.println(final_book_name); // This successfully prints "test.txt"
book_file = SD.open(final_book_name, FILE_WRITE);
if (SD.exists(final_book_name.c_str())) {
tft.print("Created file");
} else {
tft.print("Failed to create/replace\nfile!");
}
and here's the piece of the code that fails to create a file in a directory:
if (!SD.exists(DATA_DIR)) {
SD.mkdir(DATA_DIR);
}
String final_book_name = upload_book_name + ".txt";
String book_data_path = DATA_DIR;
book_data_path += "/data_" + final_book_name;
if (SD.exists(book_data_path.c_str())) {
SD.remove(book_data_path.c_str());
}
tft.println(book_data_path); // This successfully prints "DATA/data_test.txt"
File book_data_file = SD.open(book_data_path, FILE_WRITE);
if (SD.exists(book_data_path.c_str())) {
book_data_file.print(upload_book_font);
book_data_file.print("|");
book_data_file.print("0");
book_data_file.close();
} else{
tft.print("Failed to create/replace\ndata file!");
if (SD.exists(final_book_name.c_str())) {
SD.remove(final_book_name.c_str());
}
}
/DATA/test.txt
I remember SD library uses the classic 8.3 filenames anddata_test.txt
is invalid