Pages: [1]   Go Down
Author Topic: if(!SD.exists(date + ".txt")); How do I do this?  (Read 302 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 4
Posts: 289
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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:
if(!SD.exists(date + ".txt")

so that it will be evaluated as:

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

What is the operator to do this?
Logged

Arduino Uno;
Mega328

Offline Offline
Edison Member
*
Karma: 43
Posts: 1556
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
char filename[16];

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

Pete
Logged

Where are the Nick Gammons of yesteryear?

0
Offline Offline
Sr. Member
****
Karma: 4
Posts: 289
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks!  That is exactly what I needed.
Logged

Arduino Uno;
Mega328

Pages: [1]   Go Up
Jump to: