Use queue-based directory parsing instead of recursion.