read filesystem directories in one pass, then iterate in a second pass.