Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/System.Management.Automation/help/MUIFileSearcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ private string[] GetFiles(string path, string pattern)
ArrayList result = new ArrayList();
string[] files = Directory.GetFiles(path);

string regexPattern = pattern.Replace(".", @"\.");
regexPattern = regexPattern.Replace("*", ".*");
regexPattern = regexPattern.Replace("?", ".?");
var wildcardPattern = WildcardPattern.ContainsWildcardCharacters(pattern)
? WildcardPattern.Get(pattern, WildcardOptions.IgnoreCase)
: null;

foreach (string filePath in files)
{
Expand All @@ -133,11 +133,12 @@ private string[] GetFiles(string path, string pattern)
result.Add(filePath);
break;
}
// If the input is pattern instead of string, we need to use Regex expression.
if (pattern.Contains("*") || pattern.Contains("?"))
{
if (Regex.IsMatch(filePath, regexPattern))
{

if (wildcardPattern != null)
{
string fileName = Path.GetFileName(filePath);
if (wildcardPattern.IsMatch(fileName))
{
result.Add(filePath);
}
}
Expand Down