File counting with Powershell commands

前端 未结 2 833
囚心锁ツ
囚心锁ツ 2021-02-13 18:31

How can I count all files in a specific folder (and all subfolders) with the Powershell command Get-ChildItem? With (Get-ChildItem -recurse

2条回答
  •  耶瑟儿~
    2021-02-13 19:02

    I would pipe the result to the Measure-Object cmdlet. Using (...).Count can yield nothing in case there are no objects that match your criteria.

     $files = Get-ChildItem  -Recurse | Where-Object {!$_.PSIsContainer} | Measure-Object
     $files.Count
    

    In PowerShell v3 we can do the following to get files only:

     Get-ChildItem  -File -Recurse
    

提交回复
热议问题