So i got it to work on unix, but i really need it to work for windows instead. The code below will get all the files in the folder and print the last modified date. How would i go about doing this for windows?
I’m not able to help you with your code, but if you have the Microsoft compiler, it’s possible this code does the same thing:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// ...get all the files in the folder and print the last modified date.
#include <chrono>
#include <filesystem>
#include <iostream>
usingnamespace std::experimental::filesystem::v1; // Microsoft Visual Studio
int main()
{
for(constauto& it : directory_iterator("C:\\test\\")) {
auto ftime = last_write_time(it);
std::time_t cftime = decltype(ftime)::clock::to_time_t(ftime);
std::cout << it << " last modified time was "
<< std::asctime(std::localtime((&cftime)))
<< '\n';
}
}
I worked out the above code from the examples in this page http://en.cppreference.com/w/cpp/filesystem
and the related ones, but I can’t test it because I don’t have the Microsoft compiler (and my compiler doesn’t support “filesystem” yet).
Otherwise, if you have boost, this code works for sure (I’ve tested it):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// ...get all the files in the folder and print the last modified date.
#include <chrono>
#define BOOST_NO_CXX11_SCOPED_ENUMS
#include <boost/filesystem.hpp>
#undef BOOST_NO_CXX11_SCOPED_ENUMS
#include <iostream>
namespace bf = boost::filesystem;
int main()
{
for(constauto& it : bf::directory_iterator("C:\\test\\")) {
std::time_t ftime = last_write_time(it);
std::cout << it << " last modified time was "
<< std::asctime(std::localtime(&ftime))
<< '\n';
}
}
Please remember you need to link libboost_system.a and libboost_filesystem.a.