Vereinsmeisterschaften  22aa7800eae54b428d40e835886cefe1fdefdfdf
This is a software that can be used to manage the internal competition of the swimming club Illertissen called "Vereinsmeisterschaften".
Loading...
Searching...
No Matches
FilePathHelper.cs
1using System.Diagnostics;
2
4{
8 public static class FilePathHelper
9 {
17 public static string MakePathRelative(string fullPath, string rootFolder)
18 {
19 if(string.IsNullOrEmpty(fullPath))
20 {
21 return "."; // Return current directory if fullPath is empty
22 }
23 if(!IsPathFullyQualified(fullPath))
24 {
25 return fullPath;
26 }
27 // Remove any relative paths from these strings
28 fullPath = Path.GetFullPath(fullPath);
29 rootFolder = Path.GetFullPath(rootFolder);
30 return Path.GetRelativePath(rootFolder, fullPath);
31 }
32
40 public static string MakePathAbsolute(string relativePath, string rootFolder)
41 {
42 if(IsPathFullyQualified(relativePath))
43 {
44 return relativePath; // already absolute
45 }
46 else
47 {
48 return Path.GetFullPath(Path.Combine(rootFolder, relativePath));
49 }
50 }
51
58 public static bool IsPathFullyQualified(string path)
59 {
60 var root = Path.GetPathRoot(path);
61 return root != null && (root.StartsWith(@"\\") || root.EndsWith(@"\") && root != @"\");
62 }
63
71 public static bool IsPathDirectory(string path)
72 {
73 if (path == null) throw new ArgumentNullException("path");
74 path = path.Trim();
75
76 if (Directory.Exists(path))
77 return true;
78
79 if (File.Exists(path))
80 return false;
81
82 // neither file nor directory exists. guess intention
83
84 // if has trailing slash then it's a directory
85 if (new[] { "\\", "/" }.Any(x => path.EndsWith(x)))
86 return true; // ends with slash
87
88 // if has extension then its a file; directory otherwise
89 return string.IsNullOrWhiteSpace(Path.GetExtension(path));
90 }
91
97 public static void OpenWithDefaultProgram(string path)
98 {
99 using (Process fileopener = new Process())
100 {
101 fileopener.StartInfo.FileName = "explorer";
102 fileopener.StartInfo.Arguments = "\"" + path + "\"";
103 fileopener.Start();
104 }
105 }
106 }
107}