Just notice performance difference between below commands. Does anybody know why ? Just curious.
PS> gci -r *.txt # this is slower
PS> gci -r -filter *.txt # this is faster
CodePudding user response:
This is documented under -filter
Parameter.
-
Filter
Specifies a filter to qualify the Path parameter. The FileSystem provider is the only installed PowerShell provider that supports filters. Filters are more efficient than other parameters. The provider applies filter when the cmdlet gets the objects rather than having PowerShell filter the objects after they're retrieved. The filter string is passed to the .NET API to enumerate files. The API only supports * and ? wildcards.
CodePudding user response:
When you use tab completion after dash (-{tab}), first parameter being suggested is -Path
and that's where your pattern is being passed on to.
So two commands are not equivilent. The difference should be the same as between -Include
and -Filter
. Filter is always faster, as it taps into File System provider, instead of filtering only after retrieving the files.