-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtil.cs
More file actions
28 lines (26 loc) · 1.09 KB
/
Util.cs
File metadata and controls
28 lines (26 loc) · 1.09 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FTPManagement
{
class Util
{
public bool IsMatchFileName(string fileName, string pattern)
{
var regexPattern = "^" + System.Text.RegularExpressions.Regex.Escape(pattern)
.Replace("\\*", ".*")
.Replace("\\?", ".") + "$";
return System.Text.RegularExpressions.Regex.IsMatch(fileName, regexPattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
}
public bool IsUnderIgnoredDirectory(string path, string[] ignorePatterns)
{
string relativePath = path.Replace("\\", "/");
return ignorePatterns.Any(pattern =>
relativePath.Equals(pattern) ||
relativePath.StartsWith(pattern.TrimEnd('*').TrimEnd('/')) ||
relativePath.Contains(pattern.TrimEnd('*').TrimEnd('/')) && (relativePath.IndexOf(pattern.TrimEnd('*').TrimEnd('/')) + pattern.TrimEnd('*').TrimEnd('/').Length) == relativePath.Length);
}
}
}