Modified to add support for full directory output (non-flattened)