get-childitem 中 -include 和 -filter 的区别 [英] Difference between -include and -filter in get-childitem

查看:35
本文介绍了get-childitem 中 -include 和 -filter 的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能解释一下 Get-ChildItem 命令中 -Include-Filter 选项之间的区别.

Can someone please explain the difference between -Include and -Filter options in the Get-ChildItem command .

下面是我试图执行的两段代码.它们都用于查找特定目录中的文本文件:

Below are the two pieces of code that I am trying to execute . They both serve to find out the text files in a particular directory:

PS C:\Users\352997> get-childitem -path Desktop\Extras -filter *.txt


    Directory: C:\Users\352997\Desktop\Extras


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---        12/22/2014   4:05 PM        140 Expense_report.txt
-a---         1/14/2015   4:41 PM        211 Extras.txt
-a---         2/10/2015   2:46 PM        259 Learn Dutch.txt

PS C:\Users\352997> get-childitem -path Desktop\Extras -include *.txt

--上面的命令没有结果----

--The above command produces no result ----

推荐答案

  1. Filter 参数由提供者实现.它是有效的,因为在检索对象时适用.Get-PSprovider commandlet 显示实现过滤器"参数的提供程序.例如,我的上只有两个提供者系统:ActiveDirectory 和文件系统

  1. Filter parameter is implemented by provider. It is efficient because applies when retrieving the objects. Get-PSprovider commandlet shows providers that implement 'filter' parameter. For example, there are only two providers on my system:ActiveDirectory and FileSystem

Include 参数由 Powershell 实现.它仅与 Recurse 参数结合使用(如 MSDN 描述的 这里).

Include parameter is implemented by Powershell. It only works in conjunction with Recurse parameter (as MSDN describes here).

有趣的是:

get-childitem -path Desktop\Extras\ -include *.txt

什么都不返回

get-childitem -path Desktop\Extras\* -include *.txt

返回 *.txt 文件列表

returns list of *.txt files

也许这些只是实现的细微差别.

Maybe these are just nuances of the implementation.

另见这篇优秀的博文:http://tfl09.blogspot.com/2012/02/get-childitem-and-theinclude-and-filter.html

这篇关于get-childitem 中 -include 和 -filter 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆