Pages: [1]   Go Down
Author Topic: Add ability to get to SD File modified time to SD Library Request  (Read 457 times)
0 Members and 1 Guest are viewing this topic.
Virginia, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I like the simplicity of the code when using the SD library, but miss the ability to get the modified date of the files on the SD card for directory listings to know when the file originated.

I did the unthinkable and hacked the SD library to add a single function that allows me to get to the modification time.

I had considered having the function return the time (as a time_t) but discarded that approach because it added another dependancy to the library (#include <Time.h>), and my goal was to do the absolute minimum changes to the library.

I ultimately chose to have the function return the directory file (dir_t) from the underlying SdFile using the SdFile::dirEntry(dir_t* sd_dir) function.  The underlying data structure is protected from tinkering since SdFile::dirEntry does a memcopy of the internal data structure to the supplied data structure, breaking the linkage between the two.

In SD.h
Code:
...
void rewindDirectory(void);

//Add the following
void dirEntry(dir_t* sd_dir);
//End of Add

using Print::write;
...


In SD.cpp
Code:
...
void File::rewindDirectory(void) { 
  if (isDirectory())
    _file->rewind();
}

//Add the following
void File::dirEntry(dir_t* sd_dir) {
_file->dirEntry(sd_dir);
}
//End of Add

SDClass SD;
...
}


Printing the modified time then can be done with this snippet, need to do all of the initiation, etc. to get to this point

Code:

File dir;
File entry;
dir_t p;

...

entry.dirEntry(&p);
Serial.print(FAT_YEAR(p.lastWriteDate));
Serial.print(FAT_MONTH(p.lastWriteDate));
Serial.print(FAT_DAY(p.lastWriteDate));
Serial.print(FAT_HOUR(p.lastWriteTime));
Serial.print(FAT_MINUTE(p.lastWriteTime));
Serial.print(FAT_SECOND(p.lastWriteTime));
...


Any reason that adding this to the standard SD library would be a problem in future releases?
Logged

...and dinosaurs roamed the earth.....

Pages: [1]   Go Up
Jump to: