Go Down

Topic: Sdfat (Read 11529 times) previous topic - next topic



Does anyone know how to retrieve the file creation and modification date with Sdfat? I know it this information is returned with root.ls(..) command, but that returns all the files in the directory. I just want this for a specific file.




Jan 22, 2011, 02:01 am Last Edit: Jan 22, 2011, 02:08 am by davekw7x Reason: 1
Using SdFat library:

Code: [Select]

#include <SdFat.h>
#include <SdFatUtil.h>

Sd2Card  card;
SdVolume volume;
SdFile   root;
SdFile   file;

const int SDChipSelect = 9; // For my setup.

void setup(void)
   pinMode(SS_PIN, OUTPUT);    // Actually the Sd2Card constructor does this
   digitalWrite(SS_PIN, HIGH); // Make sure Ethernet SPI is not selected

   Serial.println("Type any character to start");
   while (!Serial.available())

   // If SPI_FULL_SPEED doesn't work with your setup, try SPI_HALF_SPEED
   if (!card.init(SPI_FULL_SPEED, SDChipSelect)) {
       Serial.println("card.init failed");

   // initialize a FAT volume
   if (!volume.init(&card)) {
      Serial.println("volume.init failed");
   Serial.print("Volume is FAT");

   // open the root directory
   if (!root.openRoot(&volume))
       Serial.println("openRoot failed");

   // open a file
   if (file.open(&root, "TESTFILE.TXT", O_READ)) {
       Serial.println("Opened TESTFILE.TXT");
   else {
       Serial.println("file.open failed");
   dir_t d;
   if (!file.dirEntry(&d)) {
       Serial.println("file.dirEntry failed");

   Serial.print("Created      : ");
   Serial.print(' ');

   Serial.print("Last Modified: ");
   Serial.print(' ');

   Serial.print("Last Accessed: ");

void loop(void) {}

Change the SDChipSelect definition to whatever your SD circuit uses

Note that if your SD circuit is on a separate shield and you don't have a new Ethernet shield plugged into your Arduino, you don't need the pinMode and digitalWrite to SS_PIN, but I put them there "just in case."  

Output for that file on my 8 Megabyte SD card:

Volume is FAT16


Created      : 2011-01-09 12:22:12
Last Modified: 2011-01-09 12:22:12
Last Accessed: 2011-01-21



If you have a larger SD card or microSD card formatted as FAT32 there is really, really (really) no need to reformat it when using the SdFat library.  Really.  On the other hand if you have a really small card that came as FAT12, then you need to reformat it to FAT16.



Thanks for your reply. I must have a different version of sdfat. I removed the & in front of the variables and the code worked great.



Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131