how to open a directory op SD and write a file in in

I try the code like below ,
it makes a directory if it is not present on the SD cart , but it would not write the file into this directory

can somebody help me with this?

if(SD_OK)
{
int y = year()-2000;

char dir[5];
char fileName[20];
int fileCounter=0;

sprintf(dir,"%04d",year()); //directory naam : 2013/

if (!SD.exists(dir))
{
SD.mkdir(dir);
}

do
{
fileCounter++;
sprintf(fileName,"%02d%02d%02d_%01d.csv",y,month(),day(),fileCounter);
}
while (SD.exists((dir,fileName)) && fileCounter<9); //if file in directory exist and counter<9 generate new name
logFile = SD.open((dir,fileName), O_CREAT | O_WRITE); //open file in directory

You combine a dir and a filename.
But this "SD.exists((" and "SD.open((" have double parentheses, that is very weird. Are you used with another programming language ?

Please read how to use them:

You could make a buffer and use strcat() to create the full filename with path. You have to use a '/' between them. I checked my code, and I have something like this: "/ARDUINO/LOG.TXT"

(dir,fileName)

The comma operator returns the last item in the list. The dir part of what is in the parentheses is ignored. (dir,fileName) is identical to fileName.

It is NOT how you define which directory to create the file in.

Erdin:
You combine a dir and a filename.
But this "SD.exists((" and "SD.open((" have double parentheses, that is very weird. Are you used with another programming language ?

Please read how to use them:
SD - Arduino Reference
SD - Arduino Reference

You could make a buffer and use strcat() to create the full filename with path. You have to use a '/' between them. I checked my code, and I have something like this: "/ARDUINO/LOG.TXT"

Thnx for help, i will look intro it
And no i am not commen, to programma anymore. I programmed 15years ago in c++. im try to learn the c code again