SD library, open function, file name as a String

Hi all !

I'm trying to create a code that opens different files from an SD card. Depending on the circumstances the file is different, so I'm trying to create a string with the file name that I need. I put a code where I generate two file names (file1.c and file2.c) and I try to open the files with this name from the SD card. The errors that I receive from the compiler are :
error: no matching function for call to 'SDClass::open(String&)'
SD.h:83: note: candidates are: File SDClass::open(const char*, uint8_t)

for (int i =1 ; i<3 ; i++){ 
  file_name = String("file"); 
  file_name += i;
  file_name += ".c";
  Serial.println(file_name);
  File dataFile = SD.open(file_name);
  dataFile.close();
}

It has to be something obvious, but I'm new and I can't find a way to solve it.

Many thanks

I solved it with that code. But i don't know exactly what I have done.

  char __filename[sizeof(filename)];
  filename.toCharArray(__filename, sizeof(__filename));
  File dataFile = SD.open(__filename);

But i don't know exactly what I have done.

The String class wraps a string. What you have done is unwrap the string. The SD library (rightly) thinks that you don't need crutches, and String is a crutch. The sprintf() function can populate a char array (aka a string, when the char array is properly NULL terminated).

Why do you need a for loop to iterate twice? Why are you opening (creating) and closing file1.c and file2.c every time that snippet is called?