TrailingPathDelimiter für Pfadnamen hinzufügen oder entfernen

using System.IO;

/// <summary>
/// freeware helper class for managing DirectorySeparatorChar
/// (W) 2011 by admin of codezentrale.de
/// </summary>
public static class FileSystem
{
    /// <summary>
    /// include ending DirectorySeparatorChar
    /// </summary>
    /// <param name="path">current path</param>
    /// <returns>path with ending DirectorySeparatorChar</returns>
    public static string IncludeTrailingPathDelimiter(string path)
    {
        return path.EndsWith(Path.DirectorySeparatorChar.ToString()) ? path : path + Path.DirectorySeparatorChar;
    }
    /// <summary>
    /// exclude ending DirectorySeparatorChar
    /// </summary>
    /// <param name="path">current path</param>
    /// <returns>path without ending DirectorySeparatorChar</returns>
    public static string ExcludeTrailingPathDelimiter(string path)
    {
        return path.EndsWith(Path.DirectorySeparatorChar.ToString()) ? path.Remove(path.Length, 1) : path;
    }
}