-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.cs
More file actions
31 lines (30 loc) · 1.02 KB
/
Utils.cs
File metadata and controls
31 lines (30 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
namespace LuaMCP {
public static class Utils {
/// <summary>
/// path が rootDir 以下のパスかどうかを調べる
/// </summary>
/// <param name="rootDir">完全修飾パス</param>
/// <param name="path"></param>
/// <param name="error"></param>
/// <returns></returns>
public static bool IsInDirectory(string rootDir, string path, out string? error) {
var fullPath = Path.GetFullPath(path, rootDir);
DirectoryInfo? d = File.Exists(fullPath)
? new FileInfo(fullPath).Directory
: Directory.GetParent(fullPath);
if (d == null) {
error = "directory is not exist";
return false;
}
while (d != null) {
if (d.FullName == rootDir) {
error = null;
return true;
}
d = d.Parent;
}
error = null;
return false;
}
}
}