Read only the oldest file

Hi.
I'm quite new to C++ and got a problem of reading some files from a directory.
All files is pure text, and I have no problem in reading these.
My problem is that I always have to read the oldest file without knowing the filename, and then move it to another directory and so on. Is it possible to use the timestamp instead of the filename to access the right file - read it and then move it to another directory?
Boost is what I have heard is designed to do this, but myself I have not used it yet.

My workaround is to use a system call and do a dir

1
2
3
4
5
6
7
8
9
int main()
{
// od sorts by date, b shows only file names.

// send to screen 
system ("dir /od /b");
// send to file
system ("dir /od /b > filelist.txt");
}



you would want to send this to a temp directory and use a temp file.
then read only the first line of the temp file and you have the oldest file name.

*edit*
you may also want to read
http://pubs.opengroup.org/onlinepubs/7908799/xsh/sysstat.h.html


Last edited on
Boost::Filesystem would be your best option. Cross-platform and lightweight.
http://www.boost.org/doc/libs/1_52_0/libs/filesystem/doc/index.htm
Thanks.

This solved the problem.
Topic archived. No new replies allowed.