Record exists-ends times. Use mtime() instead of stat(). Move the readdir loop outside the main status loop.