I see you have an opendir whose return value you don't check.
Perhaps the opendir fails. Then readdir returns an empty
list. This results in no files being unlinked, and could
explain the results you are seeing.
Or perhaps you are unlinking different files than you think
you are. I'd suggest adding some debugging statements around
the unlink.
Abigail
Comment on Re: unlink return code success but not deleted