locked
Exclude Sub Folders From Get-ChildItem RRS feed

  • Question

  • Get-ChildItem -Path C:\MDaemon\Queues\Remote\ -recurse -include *.MSG | Measure-Object | %{$_.Count} 

    count of the this folder is 12 but it is showing sub folder count also 184

    sub folder path : C:\MDaemon\Queues\Remote\Retry


    Microsoft technet


    Monday, February 12, 2018 9:46 AM

Answers

  • -include is a funny parameter.  You have to put a wildcard (*) at the end of the -path parameter for it to work (or -recurse).

         
    Get-ChildItem -Path C:\MDaemon\Queues\Remote\* -include *.MSG | Measure-Object |
    Select-Object count






    Monday, February 12, 2018 4:40 PM

All replies

  • Don't use "recurse"


    \_(ツ)_/

    • Proposed as answer by I.T Delinquent Monday, February 12, 2018 10:04 AM
    Monday, February 12, 2018 10:03 AM
  • without "recurse" unable to get the cound it is showing '0'

    Microsoft technet

    Monday, February 12, 2018 10:18 AM
  • Use the –File parameter
    Monday, February 12, 2018 12:06 PM
  • Can u please show me briefly.. 

    Microsoft technet

    Monday, February 12, 2018 12:56 PM
  • Can u please show me briefly.. 

    Microsoft technet

    So 

    Get-Childitem -Path <Path> -File -Recurse

    Edit:

    Get-Childitem -Path <path>-File -Recurse -Include *.<extension> | Measure-Object | %{$_.Count} 


    • Edited by Ben Lavender Monday, February 12, 2018 1:34 PM
    • Proposed as answer by Ben Lavender Monday, February 12, 2018 9:48 PM
    Monday, February 12, 2018 1:01 PM
  • (Get-ChildItem -Path <path> -filter *.msg).count

    Monday, February 12, 2018 2:32 PM
  • it is taking sub folder count also..

    Microsoft technet

    Monday, February 12, 2018 2:41 PM
  • it is taking sub folder count also..

    Microsoft technet

    • Proposed as answer by Gedae Wednesday, October 30, 2019 1:37 PM
    Monday, February 12, 2018 2:41 PM
  • it is taking sub folder count also..

    Microsoft technet


    u didn't even try my example ..
    Monday, February 12, 2018 2:56 PM
  • give me your mail id i will send output.

    vinaykampati@gmail.com


    Microsoft technet

    Monday, February 12, 2018 2:58 PM
  • -include is a funny parameter.  You have to put a wildcard (*) at the end of the -path parameter for it to work (or -recurse).

         
    Get-ChildItem -Path C:\MDaemon\Queues\Remote\* -include *.MSG | Measure-Object |
    Select-Object count






    Monday, February 12, 2018 4:40 PM
  • Not working total count showing '0'

    Microsoft technet

    Monday, February 12, 2018 9:44 PM
  • it is taking sub folder count also..

    Microsoft technet

    You’re doing “something” wrong for it to read the directories as well. I’ve just tested my second example with x3 .msg files and x1 directory and it gave me the number of .msg file count.

    Monday, February 12, 2018 9:47 PM
  • Thanku so much its working...

    Microsoft technet

    Monday, February 12, 2018 9:53 PM