openFrameworks icon indicating copy to clipboard operation
openFrameworks copied to clipboard

sorting by date a file directory content

Open Taprik opened this issue 10 years ago • 5 comments

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);
}

Taprik avatar Oct 18 '16 07:10 Taprik

This seems useful, thought I'd propose doing the date comparisons with std::filesystem functions.

bakercp avatar May 22 '17 16:05 bakercp

Isn't this already implemented? https://github.com/openframeworks/openFrameworks/blob/6947da8714177f895fa2557a27cde362e15f8dbe/libs/openFrameworks/utils/ofFileUtils.cpp#L1346

hamoid avatar May 22 '17 17:05 hamoid

Sure looks like it! Closing.

bakercp avatar May 22 '17 17:05 bakercp

wait is this in 098? I'm not able to use it

prismspecs avatar May 22 '17 21:05 prismspecs

It is in the master branch and will be available in 0.10.0+.

bakercp avatar May 22 '17 21:05 bakercp