This repository has been archived on 2023-02-02. You can view files and clone it, but cannot push or open issues or pull requests.
mfgames-nitride-cil/src/MfGames.Nitride.IO/Paths/UPathExtensions.cs

46 lines
1.1 KiB
C#

using Zio;
namespace MfGames.Nitride.IO.Paths;
/// <summary>
/// Extension methods for the UPath class.
/// </summary>
public static class UPathExtensions
{
/// <summary>
/// Gets the directory path, which excludes the directory at the end
/// of the path.
/// </summary>
/// <param name="path">The path to manipulate.</param>
/// <returns>A normalized path.</returns>
public static string GetDirectoryIndexPath(this UPath path)
{
if (path.GetNameWithoutExtension() == "index")
{
return path.GetDirectory()
.ToString()
.TrimEnd('/')
+ "/";
}
return path.ToString();
}
public static string GetParentDirectoryIndexPath(this UPath path)
{
UPath indexPath = path.GetDirectoryIndexPath();
UPath parent = indexPath.GetDirectory();
if (parent == null!)
{
parent = "/";
}
string parentPath = parent.ToString()
.TrimEnd('/')
+ "/";
return parentPath;
}
}