Question:
I was trying to do a script to list extract the folders and subfolders and the number of files for a particular path of directory. How to exclude the folders whose access is denied in the script?
I used the get-childitem
code snippet along with where {$_.permission -match "read"
, I don’t know if what I am trying is correct or not. I ended up with the following error:message:
CategoryInfo : ReadError: (\support….-242\New folder:String) [Get-ChildItem], IOException
+ FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand
Answer:
You can set your error action preference per cmdlet like:
1 2 |
Get-ChildItem -recurse -ErrorAction SilentlyContinue | ? {$_.permission -match "read"} |
Or you can set it per script using the System variable:
$ErrorActionPreference = "SilentlyContinue"
Get-Help about_CommonParameters