title: How to check if a folder has no files locked by any process?
body: <p>I am trying to write a <code>PowerShell</code> script that will check if none of the files in a particular folder is locked by any process; if true, only then delete the folder.</p>
  
  <p>One way is to check locks on each file by opening them in RW mode iteratively - see if exception occurs. But that's too cumbersome.</p>
  
  <p>Is there a way to check the same thing for a folder? I tried to use <code>Remove-Item</code> with <code>-WhatIf</code> flag but it's of no use because the command doesn't return any value - nor did it detect the locked files. If I try to run <code>Remove-Item</code> without the flag to look for exception, then it removes the free files only whereas I want to have a All or None condition.</p>