Dikshit Karki
Dikshit Karki

Reputation: 131

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?

Upvotes: 0

Views: 1330

Answers (1)

Yash Gupta
Yash Gupta

Reputation: 2485

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

Upvotes: 2

Related Questions