Go Down

Topic: [SOLVED ... I think ;)] SD.exists(myFile) ie variable file name...how? (Read 1 time) previous topic - next topic

JimboZA

Hi all,

I hope I'm missing something simple.  Code like below compiles happily, and is well known in the examples and various sketches around the place

Code: [Select]
if (SD.exists("page2.htm")) {
webFile = SD.open("page2.htm");        // open web page file
Serial.println("Opening page2");
 }


There, the file name is explicit as page2.htm and is in quotes.

So I thought I'd try with a filename as a variable, analogously to how one might Serial.print:

Code: [Select]
Serial.print("page2.htm");
Serial.print(myFile); // where page2.htm is already in the variable myFile.


Alas! When I try this, with the file name in a String parsed from an HTTP GET:

Code: [Select]
if (SD.exists(fileOne)) {
webFile = SD.open(fileOne);        // open web page file
Serial.print("Opening ");
Serial.println(fileOne);


... the compile fails with the line if (SD.exists(fileOne)) { highlit and the following message:

Quote
SD_file_parse.ino: In function 'void loop()':
SD_file_parse:100: error: no matching function for call to 'SDClass::exists(String&)'
C:\Program Files (x86)\Arduino\libraries\SD/SD.h:77: note: candidates are: boolean SDClass::exists(char*)
SD_file_parse:101: error: no matching function for call to 'SDClass::open(String&)'
C:\Program Files (x86)\Arduino\libraries\SD/SD.h:74: note: candidates are: File SDClass::open(const char*, uint8_t)


I have no clue what that's getting at....  =(

I'd be very surprised if there's no way to work with SD files through variables, so can anybody clue me in please?

TIA....

Jim

EDIT... is this because I have the variable in a String? Would it have worked with a char array? I have belatedly tumbled to that's what the error might mean.

MORE EDIT: I see there's a toCharArray(), I'm just going to see if that gets me out of this
Gone for good

el_supremo

Quote
Would it have worked with a char array?

Yes. Give it a shot and avoid using String.

Pete

JimboZA


Quote
Would it have worked with a char array?

Yes. Give it a shot and avoid using String.

Pete


Yeah it worked when I converted the String to a char array.... compiled anyway, got another problem  snuck in but it's almost midnight so that will be tomorrow's problem.

I used String to parse the HTTP GET since those String tools to do that looked way friendlier to me than using string.
Gone for good

Abhijit_Pal


Go Up