As @JimB noted, converting a relative path to an absolute path is not only OS-specific, it's context-specific: the same relative path on different systems (regardless of OS) can yield different paths; in fact, even on the same system, converting relative to absolute from different working directories can yield different paths. Again as @JimB noted, you can use path.Clean
to remove any unnecessary or reduntant relative path components (e.g. turn /dir/../otherDir/./subDir/
into /otherDir/subDir/
), but that's the closest you'll get to anything not context-sensitive.
If you just want to convert the representation, there's filepath.ToSlash
which will replace all platform-specific separators with forward slashes. If you're trying to re-use a path across systems, you could run ToSlash
on the input, store the "generic" path using forward slashes, then on the target system use filepath.FromSlash
to convert it back to the platform-specific path separator.