how to get file list sorted by time?

Can I get the file list sorted by time from old to new in programme in one directory?

from memory it’s ls -t. If not check one of the option of ls.

If you want to do it from within a program, you must build a list of all the files via opendir()/readdir() and then sort it yourself. Or you can use system (“ls -t >/tmp/file”) and read /tmp/file, but that’s ugly ;-)

FILE *fp = popen("/bin/ls -t", “r”)

would be slightly less ugly.



Well, you could always use a better
programming language :slight_smile: