Optimized the file-vs-dir code a lot.