Logic for iterating over directory structure.