Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

powershell - Difference between -include and -filter in get-childitem

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:Users352997> get-childitem -path DesktopExtras -filter *.txt


    Directory: C:Users352997DesktopExtras


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:Users352997> get-childitem -path DesktopExtras -include *.txt

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
  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

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

  3. It's interesting that:

    get-childitem -path DesktopExtras -include *.txt
    

    returns nothing

    get-childitem -path DesktopExtras* -include *.txt
    

    returns list of *.txt files

Maybe these are just nuances of the implementation.

Also see this excellent blog post: http://tfl09.blogspot.com/2012/02/get-childitem-and-theinclude-and-filter.html


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...