Reputation: 339
I am trying to find the total number of files under a directory which is present on my company's shared drive. But I do not have the permission to access some of the folders (Strictly restricted) inside several subdirectories. I am using Windows PowerShell but getting many errors saying, PERMISSION DENIED along with the path of the folder which it inaccessible. Below is the command I used,
Get-ChildItem -Recurse | Measure-Object | %{$_.Count}
My question is, Is there a way to find the total number of files in all the directories and subdirectories, ignoring those restricted files which are causing the errors?
Upvotes: 1
Views: 203
Reputation: 13176
Let me try:
Get-Childitem "C:\Users" -File -Recurse -ErrorAction SilentlyContinue |
Measure-Object |
Select-Object -ExpandProperty Count
Upvotes: 0
Reputation: 17462
just do it
(gci -Path C:\temp -File -Recurse -ErrorAction SilentlyContinue).Count
Upvotes: 1
Reputation: 1598
Powershell 3.0 and higher:
(Get-Childitem -Recurse -path x:\whatever -erroraction SilentlyContinue | where {-not ($_.PSIsContainer)}).count
You might still see errors, but you'll get an answer
Upvotes: 0