10 public static string JoinPath(IEnumerable<string> parts)
12 return '/' +
string.Join(
"/", parts);
17 return path.EndsWith(
'/') || path.EndsWith(
'\\');
22 string[] parts = path.Split(
'/',
'\\');
26 parts = parts.Skip(1).ToArray();
34 return path.StartsWith(
'/') || path.StartsWith(
'\\');
39 return path is
"/" or
"\\";
42 public static string ResolvePath(
string path,
string currentDir)
46 if (parts.Length == 0)
53 if (
IsAbsolutePath(path) || currentDir ==
"/" || currentDir ==
"\\")
55 result =
new List<string>();
59 result =
new List<string>(currentDir.Split(
'/',
'\\').Skip(1));
62 foreach (
string t
in parts)
68 case ".." when result.Count == 0:
69 throw new Exception(
"Can't go back from root");
71 result.RemoveAt(result.Count - 1);
81 if (result.Count != 0 &&
string.IsNullOrEmpty(result[result.Count - 1]))
83 result.RemoveAt(result.Count - 1);
86 return "/" +
string.Join(
"/", result);
Implements Operations to read and manipulate File System Paths.
static string[] SplitPath(string path)
static string JoinPath(IEnumerable< string > parts)
static bool IsRootPath(string path)
static bool IsAbsolutePath(string path)
static bool IsDirectory(string path)
static string ResolvePath(string path, string currentDir)
Contains the Implementation of the BadScript Virtual File System.
Contains Utility Functions and Classes.