// Copyright (C) 2018, The Duplicati Team // http://www.duplicati.com, info@duplicati.com // // This library is free software; you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as // published by the Free Software Foundation; either version 2.1 of the // License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA using System; using System.IO; namespace Duplicati.Library.Common.IO { public static class Util { /// /// A cached instance of the directory separator as a string /// public static readonly string DirectorySeparatorString = Path.DirectorySeparatorChar.ToString(); public static readonly string AltDirectorySeparatorString = Path.AltDirectorySeparatorChar.ToString(); /// /// Appends the appropriate directory separator to paths, depending on OS. /// Does not append the separator if the path already ends with it. /// /// The path to append to /// The path with the directory separator appended public static string AppendDirSeparator(string path) { return AppendDirSeparator(path, DirectorySeparatorString); } /// /// Appends the specified directory separator to paths. /// Does not append the separator if the path already ends with it. /// /// The path to append to /// The directory separator to use /// The path with the directory separator appended public static string AppendDirSeparator(string path, string separator) { return !path.EndsWith(separator, StringComparison.Ordinal) ? path + separator : path; } /// /// Guesses the directory separator from the path /// /// The path to guess the separator from /// The guessed directory separator public static string GuessDirSeparator(string path) { return string.IsNullOrWhiteSpace(path) || path.StartsWith("/", StringComparison.Ordinal) ? "/" : "\\"; } } }