How to Check if a Folder is Empty in PowerShell

When you are required to check a folder if it is really empty or not with Powershell, this tutorial can help you a lot.

Check if a Folder is Empty in PowerShell

Open PowerShell with administrative privileges and execute the following script.

if( (Get-ChildItem C:\temp | Measure-Object).Count -eq 0)
{
 echo "Folder is empty"
} else { echo "Folder is not empty" }

3 thoughts on “How to Check if a Folder is Empty in PowerShell”

  1. Avatar

    $notEmpty = Test-Path -Path C:TinyTake*
    if ($notEmpty){
    Write-Host -f red “Path is not Empty”
    } else {
    Write-Host -f green “Path is empty”
    }

    Reply
    • Avatar

      or you can do shorter version

      if (Test-Path -Path C:temp*){
      Write-Host -f red “Path is not Empty”
      } else {
      Write-Host -f green “Path is empty”
      }

      Reply
  2. Avatar

    Thanks!
    For the record, my understanding is that test-path only checks to see whether the folder EXISTS, but Get-ChildItem will confirm whether the folder is empty

    Reply

Leave a Comment

*