I would compare last change time of 2 files in SD.
I use <SD.h>'s file.timestamp(*) to set it, but i don’t know how read it!
I hope someone can help me, thanks.
I would compare last change time of 2 files in SD.
I use <SD.h>'s file.timestamp(*) to set it, but i don’t know how read it!
I hope someone can help me, thanks.
Here is a sketch for the SdFat library that opens each file in the root directory and prints
file_name year-month-day hour:minute:second
for the last write date and time.
/*
* Open all files in the root dir and print their filename
*/
#include <SdFat.h>
// SD chip select pin
const uint8_t chipSelect = SS;
// file system object
SdFat sd;
SdFile file;
// define a serial output stream
ArduinoOutStream cout(Serial);
//------------------------------------------------------------------------------
void setup() {
dir_t dir;
char name[13];
Serial.begin(9600);
// initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
// breadboards. use SPI_FULL_SPEED for better performance.
if (!sd.begin(chipSelect, SPI_HALF_SPEED)) sd.initErrorHalt();
// open next file in root. The volume working directory, vwd, is root
while (file.openNext(sd.vwd(), O_READ)) {
file.getFilename(name);
file.dirEntry(&dir);
cout << name << ' ';
cout << FAT_YEAR(dir.lastWriteDate) << '-' << setfill('0');
cout << setw(2) << (int)FAT_MONTH(dir.lastWriteDate) << '-';
cout << setw(2) << (int)FAT_DAY(dir.lastWriteDate) << ' ';
cout << setw(2) << (int)FAT_HOUR(dir.lastWriteTime) << ':';
cout << setw(2) << (int)FAT_MINUTE(dir.lastWriteTime) << ':';
cout << setw(2) << (int)FAT_SECOND(dir.lastWriteTime) << endl;
file.close();
}
cout << "Done" << endl;
}
//------------------------------------------------------------------------------
void loop() {
}
Here is example output:
LOGFILE.BIN 2000-01-01 01:00:00
DATE.TXT 2012-07-14 10:39:32
Done
The time-stamp has not been set on the first file.