Search and delete empty folders on Windows using PowerShell

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.

Search and delete empty folders on Windows using PowerShell Picture 1

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.

Search and delete empty folders on Windows using PowerShell Picture 2

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.

Search and delete empty folders on Windows using PowerShell Picture 3

+ 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

}

}

Search and delete empty folders on Windows using PowerShell Picture 4

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.

Search and delete empty folders on Windows using PowerShell Picture 5

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 !

5 ★ | 1 Vote

May be interested

  • Delete Files on Mac - Empty Trash or Secure Empty Trash?Delete Files on Mac - Empty Trash or Secure Empty Trash?
    deleting files in mac os is not a difficult matter in any way, but it can cause confusion. most people know how to drag files into the trash in the dock, but to really delete them, there are two options in the finder menu - empty trash and secure empty trash.
  • How to hide a specific folder from search results on Windows 11How to hide a specific folder from search results on Windows 11
    sometimes, for privacy reasons, you may want to hide certain folders or folders so that they don't appear in the search results returned every time someone makes a query with windows 11 search. .
  • Instructions for hiding files and folders in Windows 10 SearchInstructions for hiding files and folders in Windows 10 Search
    in windows 10, the cortana box or windows search item can help you search all files and folders in your computer. however, if you don't want others to view certain files or folders, you can hide them in windows search results. let's see how to hide a folder so it doesn't appear in the search results of file explorer, cortana or search item in the taskbar!
  • How to Change Indexing Options in Windows 8How to Change Indexing Options in Windows 8
    the windows search index is a collection of folders that windows keeps a constant up-to-date database of for quick searches. these folders are always being scanned so that windows search can find files in them instantly. you can add...
  • About PowerShellAbout PowerShell
    windows powershell is a command line utility and new scripting language provided by microsoft. why should i study and care about powershell? because it is a new-style utility? of course, every new utility is claimed to be 'different' from the old ones, but powershell has some components that really distinguish it from other utilities.
  • What is the directory $ WINDOWS. ~ BT, can delete $ WINDOWS. ~ BT or not?What is the directory $ WINDOWS. ~ BT, can delete $ WINDOWS. ~ BT or not?
    folders such as $ windows. ~ bt and $ windows. ~ ws are directories related to the windows 10 upgrade process. these folders may appear on windows 7, 8 and 10 and more. , these folders are hidden folders, so to see these directories you have to perform some additional operations to display the directory.
  • Instructions for fixing errors 'Cannot delete folder: The directory is not empty'Instructions for fixing errors 'Cannot delete folder: The directory is not empty'
    'cannot delete / access denied' hay 'không thể xóa thư mục: những thư mục không phải trống' is one of the most common errors in windows xp, windows vista, windows 7 and windows 8. this error occurs while you try delete a folder on the system.
  • How to delete folder and file search history on File ExplorerHow to delete folder and file search history on File Explorer
    clearing file explorer history deletes information windows has saved about the files and folders you use, as well as what you've typed into the address bar and run dialog box.
  • What is Windows PowerShell? How to use Windows PowerShellWhat is Windows PowerShell? How to use Windows PowerShell
    do you want to learn the features of windows powershell but don't know how? suggestions for you what is windows powershell? the most convenient way to use windows powershell.
  • Instructions on how to use PowerShell in Windows Server 2012Instructions on how to use PowerShell in Windows Server 2012
    what is powershell? windows powershell is a command-line shell language interpreter and scripting language specifically designed for system administrators. built on the .net framework, windows powershell helps it professionals control and automate windows operating system administration tasks as well as applications running on windows server environments.