List empty directories on Windows

We were often faced with the problem that we would have liked to know which folders or directories below a higher-level directory are empty and therefore actually not needed. Unfortunately it is not so easy to find empty folders or directories .

However, there is a short PowerShell command to output a list of empty directories . In this case, the entire PowerShell line is as follows.

Get-ChildItem -Path “DRIVE: directory” -Recurse -Directory | ForEach-Object -Process {if ($ false -eq $ _. GetFileSystemInfos ()) {$ _. FullName}}

The only thing you have to adjust in this PowerShell line is the ” variable ” ” DRIVE: directory “. Here you have to insert the exact path you want to search for empty subfolders.

In our example, we searched our user profile directory ” C: Users Windows FAQ ” for empty subfolders , as you can see here in the figure below.

List empty subdirectories

As you can see, 3 directories are listed as output below the command, all of which are completely empty and contain no further files or subfolders. In our example, these are the subfolders ” Posts “, ” Images ” and ” Downloads “.

If the output of the list in the PowerShell console is not enough for you because the list of empty folders may be too long, you can also redirect the entire output to a text file by appending the following to the command.

Get-ChildItem -Path “DRIVE: directory” -Recurse -Directory | ForEach-Object -Process {if ($ false -eq $ _. GetFileSystemInfos ()) {$ _. FullName}} > C: FOLDER FILE NAME.TXT

We have marked the corresponding parameter RED, which redirects the output to a text file.

Empty folder list

This gives you the opportunity to process a list of numerous empty directories .

In a further post, we went into the possibility of deleting folders in a targeted manner and keeping the most current folders .

 

administrator