sorting by date a file directory content
If have changed my opendrameworks to make it sorts content by date. Usefull sometimes...
IN the header of ofFileUtils
void sortByDate();
in ofFileUtils.cpp
bool byDate(const ofFile& a, const ofFile& b) {
struct stat st1;
struct stat st2;
int date1, date2;
int err1 = stat(a.getAbsolutePath().c_str(), &st1);
int err2 = stat(b.getAbsolutePath().c_str(), &st2);
if (err1 == 0) {
date1 = st1.st_mtime;
}
else {
ofLogError("ofDirectory") << "sortByDate(): stat() failed for file 'a' while sorting by date.";
return false;
}
if (err2 == 0) {
date2 = st2.st_mtime;
}
else {
ofLogError("ofDirectory") << "sortByDate(): stat() failed for file 'b' while sorting by date.";
return false;
}
return date1 < date2;
}
void ofDirectory::sortByDate() {
ofSort(files, byDate);
}
This seems useful, thought I'd propose doing the date comparisons with std::filesystem functions.
Isn't this already implemented? https://github.com/openframeworks/openFrameworks/blob/6947da8714177f895fa2557a27cde362e15f8dbe/libs/openFrameworks/utils/ofFileUtils.cpp#L1346
Sure looks like it! Closing.
wait is this in 098? I'm not able to use it
It is in the master branch and will be available in 0.10.0+.