Search and delete empty folders on Windows using PowerShell

How to search and delete empty folders on Windows operating system? Trick to use Windows PowerShell to find and delete empty folders on Windows 10

After a long time of using the computer (here I'm talking about is the Windows 10 operating system), after installing more software, as well as uninstalling software . often it will leave messages empty folders (these folders are folders containing temporary files or folders left over after you perform software removal).

Although these empty folders usually do not have too much impact on the process of using the computer, leaving too many useless empty folders will also somewhat slow down data access from the hard drive, so I I recommend that you delete them.

Of course you can find and delete them manually, but the reason is that these empty folders are often scattered all over the hard drive, so it is very difficult to delete them manually. not very feasible.

There are also some software to support this work, but if you do not want to use software, there is still a way for you.

In this article, I will show you how to delete empty folders on Windows 10 automatically without using software.

How to find and delete empty folders on Windows 10 using PowerShell

In this article, we will use the PowerShell tool - a tool created by Microsoft with the purpose of replacing the traditional Command Prompt.

If the Command Prompt uses a fairly simple programming language, Powershell with the addition of Windows Scripting Host, VBScript, etc. will give you more rights to intervene in the Windows system more deeply.

However, it is only suitable for IT administrators and professional users, because for most basic users, PowerShell's command lines are quite confusing and confusing, especially it distinguishes both uppercase and lowercase letters in the command.

Perform:

+ Step 1: First, you open Windows PowerShell with Administrator rights by right-clicking on the Start button => and selecting Windows PowerShell (Admin).

Or you can press the Windows + X key combination => and then select Windows PowerShell (Admin) in the Menu that appears.

Picture 1 of Search and delete empty folders on Windows using PowerShell

If the menu that pops up doesn't have PowerShell but is a Command Prompt, it's because you've turned it off in the settings.

To show it again, right-click on the Taskbar => and select Taskbar Settings, in the settings window of this Taskbar => scroll down and turn the switch OFF => to ON in the line:

Replace Command Prompt with Windows PowerShell in the menu when i right-click the start button or press Windows Key + X.

Picture 2 of Search and delete empty folders on Windows using PowerShell

Or another way for those of you who do not want to change the settings is that you can enter the powershell command into the Windows 10 search box (to open the search box you use the Windows + S combination)

=> Then right-click on the Windows PowerShell application in the search results => And select Run as Administrator, you can also run PowerShell with Administrator rights on Windows 10.

Picture 3 of Search and delete empty folders on Windows using PowerShell

+ Step 2: Now copy and paste the command lines below into the Windows Powershell window => and Enter to start searching for empty folders.

Remember to replace the C: in the $SomePath= variable with the path of the drive, or directory where you want to check if it has an empty directory.

The following command:

$SomePath='C:'

Get-ChildItem -Path $SomePath -Recurse -Directory | ForEach-Object -Process {

if ($false -eq $_.GetFileSystemInfos())

{

$_.FullName

}

}

Picture 4 of Search and delete empty folders on Windows using PowerShell

Immediately, a list of multiple directories in the directory you specified in the $SomePath variable will appear.

+ Step 3: Your job now is to access these paths with Windows Explorer (Windows + E) and delete it.

Picture 5 of Search and delete empty folders on Windows using PowerShell

Similarly, if I want to check the Games folder in the D: drive, I will change the above code to: $SomePath='D:Games'…. => then Enter is okay.

With this trick, you don't necessarily have to use Windows PowerShell with Admin rights, but if you run it normally, there will be a few system folders that PowerShell does not have access to to be able to detect empty folders.

Besides, there are still folders that even if you run PowerShell as Administrator, it cannot be detected. Usually these are folders created by the Windows system to ensure operation, so if you find them, they should not be deleted.

Conclude

So I have just instructed you in detail how to find and delete empty folders on Windows 10 without installing any 3rd party software. Hope this article will be useful to you. Good luck !

Update 07 September 2021
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile