Pages: [1]   Go Down
Author Topic: how to open a directory op SD and write a file in in  (Read 971 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Edison Member
*
Karma: 58
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
http://arduino.cc/en/Reference/SDexists
http://arduino.cc/en/Reference/SDopen

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"
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
(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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
http://arduino.cc/en/Reference/SDexists
http://arduino.cc/en/Reference/SDopen

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
Logged

Pages: [1]   Go Up
Jump to: