Go Down

Topic: if(!SD.exists(date + ".txt")); How do I do this? (Read 365 times) previous topic - next topic

jerseyguy1996

Didn't know really how to describe this in the subject line.  I have:

Code: [Select]
char date[9]

which contains "13_01_21" (but this will obviously change each day) and I would like to have ".txt" appended to it in:

Code: [Select]
if(!SD.exists(date + ".txt")

so that it will be evaluated as:

Code: [Select]
if(!SD.exists("13_01_21.txt"));

What is the operator to do this?
Arduino Uno;
Mega328

el_supremo

There is a way to do this with String but String has bugs in it. You would be a lot better off to use a char array and sprintf - there are other ways too, such as using strcpy and strcat.
Code: [Select]

char filename[16];

  sprintf(filename,"%s.txt",date);
  if(!SD.exists(filename)) {
    // The file doesn't exist
  } else {
    // The file does exist
  }


Pete

jerseyguy1996

Arduino Uno;
Mega328

Go Up