in reply to How to tell if a Directory is Empty

To save time on large directories, you will probably want to add a last; after your $i++;. That way, the loop will never run more than three iterations.