powershelldirectory-traversal

How to count the number of files not of certain types


The code below counts the number of files of certain types in a directory and subdirectories:

$filetype = @("*.jpg", "*.jpeg","*.png","*.gif", "*.bmp")
$file_count = Get-ChildItem -Path $filepath -Include $filetype -Recurse -File | Measure-Object | %{$_.Count}
$output = "images: `t" + $file_count
Write-Output $output;

How would I count the number of all files that are not of these types?


Solution

  • Just replace -Include $filetype with -Exclude $filetype