File tree Expand file tree Collapse file tree 1 file changed +9
-8
lines changed
src/System.Management.Automation/help Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -122,9 +122,9 @@ private string[] GetFiles(string path, string pattern)
122
122
ArrayList result = new ArrayList ( ) ;
123
123
string [ ] files = Directory . GetFiles ( path ) ;
124
124
125
- string regexPattern = pattern . Replace ( "." , @"\." ) ;
126
- regexPattern = regexPattern . Replace ( "*" , ".*" ) ;
127
- regexPattern = regexPattern . Replace ( "?" , ".?" ) ;
125
+ var wildcardPattern = WildcardPattern . ContainsWildcardCharacters ( pattern )
126
+ ? WildcardPattern . Get ( pattern , WildcardOptions . IgnoreCase )
127
+ : null ;
128
128
129
129
foreach ( string filePath in files )
130
130
{
@@ -133,11 +133,12 @@ private string[] GetFiles(string path, string pattern)
133
133
result . Add ( filePath ) ;
134
134
break ;
135
135
}
136
- // If the input is pattern instead of string, we need to use Regex expression.
137
- if ( pattern . Contains ( "*" ) || pattern . Contains ( "?" ) )
138
- {
139
- if ( Regex . IsMatch ( filePath , regexPattern ) )
140
- {
136
+
137
+ if ( wildcardPattern != null )
138
+ {
139
+ string fileName = Path . GetFileName ( filePath ) ;
140
+ if ( wildcardPattern . IsMatch ( fileName ) )
141
+ {
141
142
result . Add ( filePath ) ;
142
143
}
143
144
}
You can’t perform that action at this time.
0 commit comments