public static ReadOnlySpan <char> GetDirectoryName(ReadOnlySpan <char> path) { if (PathInternal.IsEffectivelyEmpty(path)) { return(ReadOnlySpan <char> .Empty); } int directoryNameOffset = Path.GetDirectoryNameOffset(path); return(directoryNameOffset < 0 ? ReadOnlySpan <char> .Empty : path.Slice(0, directoryNameOffset)); }
public static string GetDirectoryName(string path) { if (path == null || PathInternal.IsEffectivelyEmpty(path.AsSpan())) { return((string)null); } int directoryNameOffset = Path.GetDirectoryNameOffset(path.AsSpan()); return(directoryNameOffset < 0 ? (string)null : PathInternal.NormalizeDirectorySeparators(path.Substring(0, directoryNameOffset))); }
// In case of link target being relative: // Preserve the full path of the directory of the previous path // so the final target is returned with a valid full path static void GetLinkTargetFullPath(ref ValueStringBuilder sb, ReadOnlySpan <char> linkTarget) { if (PathInternal.IsPartiallyQualified(linkTarget)) { sb.Length = Path.GetDirectoryNameOffset(sb.AsSpan()); sb.Append(PathInternal.DirectorySeparatorChar); } else { sb.Length = 0; } sb.Append(linkTarget); }