Check if a file is empty using PowerShell

To check if a file is empty using PowerShell in Windows, you can use the following command:

if ((Get-Item 'path\to\your\file.txt').length -eq 0) {
  Write-Host "The file is empty."
} else {
  Write-Host "The file is not empty."
}

Replace 'path\to\your\file.txt' with the actual path to your file. This command checks the length of the file. If the length is 0, it means the file is empty; otherwise, it contains some data.

Leave a Comment