1using System.Diagnostics;
8 public static class FilePathHelper
17 public static string MakePathRelative(
string fullPath,
string rootFolder)
19 if(
string.IsNullOrEmpty(fullPath))
23 if(!IsPathFullyQualified(fullPath))
28 fullPath = Path.GetFullPath(fullPath);
29 rootFolder = Path.GetFullPath(rootFolder);
30 return Path.GetRelativePath(rootFolder, fullPath);
40 public static string MakePathAbsolute(
string relativePath,
string rootFolder)
42 if(IsPathFullyQualified(relativePath))
48 return Path.GetFullPath(Path.Combine(rootFolder, relativePath));
58 public static bool IsPathFullyQualified(
string path)
60 var root = Path.GetPathRoot(path);
61 return root !=
null && (root.StartsWith(
@"\\") || root.EndsWith(
@"\") && root !=
@"\");
71 public static bool IsPathDirectory(
string path)
73 if (path ==
null)
throw new ArgumentNullException(
"path");
76 if (Directory.Exists(path))
79 if (File.Exists(path))
85 if (
new[] {
"\\",
"/" }.Any(x => path.EndsWith(x)))
89 return string.IsNullOrWhiteSpace(Path.GetExtension(path));
97 public static void OpenWithDefaultProgram(
string path)
99 using (Process fileopener =
new Process())
101 fileopener.StartInfo.FileName =
"explorer";
102 fileopener.StartInfo.Arguments =
"\"" + path +
"\"";