[TASK] Replace nested dirname calls with using the levels parameter