Get date creation of a file or time stamp


#1

I been trying to get date of creation of a file in android but no success so far i had try this to methods but no one is working, anyone knows another way?

1.-std::filesystem::last_write_time(file);

2.-auto lastModifiedTime = std::filesystem::last_write_time(ofToDataPath(“Scripts/myScript.py”));


#2

the second one should work fine, what problem do you have?


#3

Code run’s but i’m getting this values:


#4

how are you printing it? last_write_time returns file_time_type: https://en.cppreference.com/w/cpp/filesystem/last_write_time which you can compare with other times… but probably just prints a number unless you convert it to a readable format. the reference for the function above also has an example on how to print it as a human readable format


#5

Gotcha, i’m printing using ofLog() maybe that’s why


#6
 std::time_t cftime = decltype(ftime)::clock::to_time_t(ftime);
    std::cout << "File write time is " << std::asctime(std::localtime(&cftime)) << '\n';

I guess is this part without local time but when i write the code it say’s that can’t resolve clock container


#7

Hi Arturo coudn’t really get the code to work any hint?

Thanks.


#8

This worked for me in macOS

auto currentLocale = std::filesystem::last_write_time(ofToDataPath(“Scripts/” + filename.get()));
std::tm * ptm = std::localtime(&currentLocale);
char buffer[32];
// Format: Mo, 15.06.2009 20:20:00
std::strftime(buffer, 32, “%a, %d.%m.%Y %H:%M:%S”, ptm);
ofLog()<<buffer;

I have found it in: https://stackoverflow.com/questions/997512/string-representation-of-time-t
Assuming that the file_time_type can be casted to std::time_t.

Don’t know if it will work on android


#9

Cool! it worked on android.