Check the manual for:
opendir(), readdir(), closedir() (under "Directory functions"), fileatime(), filemtime(), unlink(), is_file() ("Filesystem functions"), while(){} ("Control structures")
Also, search-the-whole-directory thing appeard on this forum many times, so you may want to search it.
If you get stuck with something specific, feel free to post.
P.S. Be careful for "special" dirs: "." and "..".