Datalog to SD card filename [Solved]

I am datalogging a lot of data to a file on an SD card using the Ethernet shield and a RTC. i collect alot of datapoints overtime and this makes for some long files. I would like some input on if it is possible to do a variable filename in this comand. If possible i would like to change the file name on a monthly or even yearly basis. After you have 700 or so lines of data it becomes unmanageable. I have tried using a string but it seems it will not accept a string in place of using the DataLogFile or “DATA.CSV”. Idealy, i would like to end up with multiple files on the SD card with data from a set period of time.

#include <Wire.h>
#include <Time.h>
#include <SdFat.h>
#include <SdFatUtil.h>
#include <SPI.h>
#include <Ethernet.h>

#define DataLogFile “DATA.CSV”

if (!, O_RDWR | O_CREAT | O_AT_END)) {
error(“open file failed”);

I had tried building a string I found the string was fine and worked as expected.
DataFile = “”";
DataFile += “DAT”;
DataFile += String(year());
DataFile += “.CSV”";

End resut = “DAT2012.CSV”
However, when i replace DataLogFile with the string DataFile, as expected it errors.
no matching function for call to SdFile::open(string&,int)

If anyone has any suggestions, i would be greatful.

Instead of End resut = "DAT2012.CSV" try saving it without the double quotes as End resut = DAT2012.CSV

DataFile += "DAT";
DataFile += String(year());
DataFile += ".CSV";

C takes double quotes to take literal values for strings. If you are passing a string, you don't need the quotes. For e.g. I can type: Serial.print("Hello World1"); This will output: Hello World!

or I can do it like char Str[20]="Hello World!"; Serial.print(Str); This will not output: "Hello World!" It will give the same output as above.

So double quotes are only to tell what we are entering is a string to C. If we are sending a string, its already obvious to compiler.

Thanks for your info it did help. Seems string is not a replacement for a char array which was half my problem but you were definately right about the \" it was unnecessary. At first i was attempting to do it without the \", but i was still getting SdFile::open(string&,int). the string cast i had been using didn't seem to work as i had thought it did. so once i changed to char DataFile[] = it worked like a charm.

String DataFile;
DataFile = "\"";
DataFile += "DATA";
DataFile += String(year());
DataFile += ".CSV\"";

replaced with

char DataFile[]= "DAT20XX.CSV";
DataFile[5]= Tens+48;       // Places the 10s digit in filename as ASCII
DataFile[6]= Ones+48;       // Places the 1s digit in filename as ASCII

Seems using the MEGA 2560 + Ethernet Shield for my first arduino experince has left me making an assumption on things i shouldn't have. that will learn me to stick to what i know should work. Thank you for the help