Error when creating a text file on SD card

Hi,

I'm trying to create a text file on the SD card with a variable name defined with the date and time (ex: 170504-12h59.txt) but the code line myFile.open(filename, O_RDWR | O_CREAT | O_AT_END) is returning me an error and I can't find why...
The filename variable is array of character and its value is the same as the example above.

There is the code I use to format the filename and create the file:

readDS1307time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
day=int(dayOfMonth);
mont=int(month);
String strnomfichier =" ";
String strmois =" ";
String strjour =" ";
String strminute =" ";

if(month < 10){
strmois = '0'+String(mont);
}
else{
strmois = String(mont);
}
if(day < 10){
strjour = '0'+String(day);
}
else{
strjour = String(day);
}
if(minute < 10){
strminute = '0'+String(minute);
}
else{
strminute = String(minute);
}
strnomfichier = String(year) + strmois + strjour +'-'+ String(hour) + 'h' + strminute;
strnomfichier = strnomfichier + ".txt";
Serial.println(strnomfichier);
char filename[strnomfichier.length()+1];
strnomfichier.toCharArray(filename, sizeof(filename));
Serial.println(filename);

// open the file for write at end like the Native SD library
if(!myFile.open(filename, O_RDWR | O_CREAT | O_AT_END)) {
lcd.setCursor(0,1);
lcd.print("Error");
sd.errorHalt("opening file for write failed");
}

If some one sees something I missed, I would need a hand,
Thanks

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. Using code tags and other important information is explained in the How to use this forum post. Please read it.

Nathanv:
the code line myFile.open(filename, O_RDWR | O_CREAT | O_AT_END) is returning me an error

Don't you think it would have been helpful to post the error?

What do you expect that code to do?

pert:
What do you expect that code to do?

OK, I see now, they do that in the SdFatSize example:
https://github.com/greiman/SdFat/blob/master/examples/%23attic/SdFatSize/SdFatSize.ino#L25