Sicherung
This commit is contained in:
44
FSI.Lib/FSI.Lib/CompareNetObjects/FileHelper.cs
Normal file
44
FSI.Lib/FSI.Lib/CompareNetObjects/FileHelper.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace FSI.Lib.CompareNetObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper methods for files and directories
|
||||
/// </summary>
|
||||
public static class FileHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Get the current directory of the executing assembly
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string GetCurrentDirectory()
|
||||
{
|
||||
#if NETSTANDARD
|
||||
string basePath = AppContext.BaseDirectory;
|
||||
#else
|
||||
string basePath = AppDomain.CurrentDomain.BaseDirectory;
|
||||
#endif
|
||||
return PathSlash(basePath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensure the passed string ends with a directory separator character unless the string is blank.
|
||||
/// </summary>
|
||||
/// <param name="path">The string to append the backslash to.</param>
|
||||
/// <returns>String with a "/" on the end</returns>
|
||||
public static String PathSlash(string path)
|
||||
{
|
||||
string separator = Convert.ToString(Path.DirectorySeparatorChar);
|
||||
|
||||
if (path.Length == 0)
|
||||
return path;
|
||||
else if (path.EndsWith(separator))
|
||||
return path;
|
||||
else
|
||||
return path + separator;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user