Replace dirname($path) with $dir