[solved] SD card can't make files, can write to existing ones though.

Hello

I have been using the SD library to write text to known files for a while now, but I recently added a RTC to my setup, and now I want to make files with the currentdate as the filename. Reading the SD library SD.open should create a file if it doesn't exist, but it gives me no error, and when I check if the file exists with if (myFile) I receive a false.

This is the code part I use for making/opening the file

String filename = "" + String(getCurrentDate()) + ".txt";

....

String dataString = "somedata"; //The datastring part works, I have old files filled with data

    File dataFile = SD.open(filename, FILE_WRITE);
    if (dataFile) {
      dataFile.println(dataString);
      dataFile.close();
      Serial.println(dataString);
    }
    else {
      Serial.println("error opening " + filename);
    }

Am I doing something wrong or is my SD card hardware failing on me?

Is there limitation on the filename length?

ieee488: Is there limitation on the filename length?

In the code? It is just "DD-MM-YYYY.txt", so today would be "25-02-2016.txt". That is not much bigger than "example.txt" used in the examples

Have you tried hard coding a file name just as you wrote there to make sure the rest of your program is correct?

You should print out filename just to make sure what you think you want is what you actually have.

"25-02-2016.txt". That is not much bigger than "example.txt" used in the examples

Not much bigger, but critically so. There is an 8.3 format limitation on names, and your name is 10.3

I believe that SdFat.h supports long file names, but SD.h does not. Do some searching in the forum search box with "SD long file names".

ieee488: Have you tried hard coding a file name just as you wrote there to make sure the rest of your program is correct?

You should print out filename just to make sure what you think you want is what you actually have.

I did that, but it seesm that I am using a filename that is too long

cattledog: Not much bigger, but critically so. There is an 8.3 format limitation on names, and your name is 10.3

I believe that SdFat.h supports long file names, but SD.h does not. Do some searching in the forum search box with "SD long file names".

I will lookg into that SdFat library, thanks

It seems that indeed the SD.h can't make files longer than 8.3 characters long, So I removed the "-" from my date string, and safe it that way. Thank!