
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get Empty Files in Windows OS Using PowerShell
To get the list of empty files in Windows OS using PowerShell, there are two ways,
a) Using Length parameter. We will count the length of the file. If it is 0 then the file is empty as shown below.
Get-ChildItem C:\Temp\ -Recurse | where{$_.Length -eq 0} | Select @{N='EmptyFiles';E={$_.FullName}}
Output:
b) Another method is a long one that we don’t want to go into. We need to check each file's content and if it is empty then we will declare that file as an empty file.
Get-ChildItem C:\Temp -Recurse -File | foreach{ if((Get-Content $_.FullName) -eq $null){ $_.FullName }
This method is quite slow because it scans the entire content of each file. It is always better to use the first method.
Advertisements