Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between -include and -filter in get-childitem

Tags:

powershell

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 ----

like image 404
Subhayan Bhattacharya Avatar asked Aug 31 '25 15:08

Subhayan Bhattacharya


1 Answers

  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 Desktop\Extras\ -include *.txt
    

    returns nothing

    get-childitem -path Desktop\Extras\* -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

like image 100
Kostia Shiian Avatar answered Sep 02 '25 05:09

Kostia Shiian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!