How to find all the empty subfolders inside the folder using powershell?

I have a list of folders and each folder has subfolders.

I want to scan all main folders and subfolders to list out the empty folders.

My expected output is the list of folders and their path.

For example:

C:\Users\someUser\Downloads\ 2020-01-16
C:\Users\someUser\Downloads\ 2021-01-12

I tried using this:

Get-ChildItem -Path "C:\Users\someUser\Downloads\" -Recurse | Measure-Object

but its giving me the total count of parent folder.

How can I get all the folders and subfolders empty?

1 Answer

This should get you going:

$foldersList = Get-ChildItem C:\Users\someUser\Downloads\ -Recurse | Where-Object {$_.PSIsContainer -eq $True}
$foldersList | Where-Object {$_.GetFiles().Count -eq 0} | Select-Object FullName
2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like