Extract basename first to have the name be consistent regardless of how it was called.