Archived
Checkpoint
This commit is contained in:
@@ -1,14 +1,10 @@
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Common.Extensions;
|
||||
namespace Common.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Extensions for the string object type
|
||||
/// </summary>
|
||||
public static class StringExtensions
|
||||
{
|
||||
private static readonly Regex patternRegex = new Regex(@"^\*$");
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this string contains the specified string. Not case sensitive.
|
||||
/// </summary>
|
||||
@@ -24,18 +20,20 @@ public static class StringExtensions
|
||||
/// </summary>
|
||||
/// <param name="self"></param>
|
||||
/// <returns></returns>
|
||||
public static ICollection<string> ExpandPath(this string self)
|
||||
public static IEnumerable<string> ExpandPath(this string self)
|
||||
{
|
||||
string pattern = Path.GetFileName(self);
|
||||
if (patternRegex.IsMatch(pattern))
|
||||
var parts = self.Split(Path.DirectorySeparatorChar);
|
||||
|
||||
var fileName = parts.Last();
|
||||
if (fileName.Contains('*') || fileName.Contains('?'))
|
||||
{
|
||||
return Directory.GetFiles(
|
||||
self.Substring(0, self.Length - pattern.Length),
|
||||
pattern,
|
||||
SearchOption.TopDirectoryOnly
|
||||
);
|
||||
// Path contains file pattern
|
||||
|
||||
var path = Path.Combine(parts.SkipLast(1).ToArray());
|
||||
return Directory.EnumerateFiles(path, fileName);
|
||||
}
|
||||
|
||||
// Path contains no pattern
|
||||
return new[] { self };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user