{"id":8771,"date":"2019-04-21T17:32:53","date_gmt":"2019-04-21T17:32:53","guid":{"rendered":"http:\/\/198.58.113.91\/blog\/?p=8771"},"modified":"2023-07-05T20:20:29","modified_gmt":"2023-07-05T14:50:29","slug":"find-and-delete-empty-folders-windows","status":"publish","type":"post","link":"https:\/\/www.winhelponline.com\/blog\/find-and-delete-empty-folders-windows\/","title":{"rendered":"How to Find and Remove Empty Folders in Windows"},"content":{"rendered":"<p>Over time, hundreds of empty folders and junk files may take up your hard disk. While the junk files occupy disk space and can be cleaned up using <a href=\"https:\/\/www.winhelponline.com\/blog\/delete-windows-old-folder-previous-versions\/\">Disk Cleanup<\/a> or <a href=\"https:\/\/www.winhelponline.com\/blog\/storage-app-find-files-taking-disk-space-w10\/\">Storage settings<\/a>, the empty directories remain.<\/p>\n<p>The empty folders don&#8217;t take up disk space, but to organize your data better, you may want to prune them every once in a while.<\/p>\n<p>This article discusses different methods to find and remove empty folders on your computer.<!--more--><\/p>\n<div id=\"toc\">\n<h4>Find\/Remove Empty Directories in Windows<\/h4>\n<ol>\n<li><a href=\"#red\">Using &#8220;Find Empty Files-n-Folders<strong>&#8220;<\/strong> or &#8220;Empty Folder Cleaner&#8221;<\/a> (GUI)<\/li>\n<li><a href=\"#rd\">Using <em>For<\/em> and <em>rd<\/em> commands<\/a><\/li>\n<li><a href=\"#robocopy\">Using Robocopy<\/a><\/li>\n<li><a href=\"#powershell\">Using PowerShell<\/a><\/li>\n<li><a href=\"#script\">Using Windows Scripting<\/a><\/li>\n<li><a href=\"#delempty\">Using DelEmpty.exe<\/a><\/li>\n<li><a href=\"#nirsoft\">Using SearchMyFiles utility from Nirsoft<\/a> (GUI)<\/li>\n<\/ol>\n<\/div>\n<h2>How to Find and Remove Empty Folders in Windows?<\/h2>\n<p>An empty folder or directory is one that has no file or sub-directory in it. Empty folders don&#8217;t take any disk space, but too many of them can be a nuisance. To find and remove them, use one of the methods below.<\/p>\n<p><em><strong>Important:<\/strong> Running an automated tool or batch file to delete empty folders in the entire system drive recursively is usually not recommended. This is because some programs may fail to work and throw a bizarre error when it finds an essential folder missing. As always, the standard warning applies. Be sure to have appropriate backups, preferably on an external drive, before manipulating the file system or the Windows registry.<\/em><\/p>\n<p><em><strong>RELATED:<\/strong> <a href=\"https:\/\/www.winhelponline.com\/blog\/find-and-delete-zero-byte-files-recursively-windows\/\">Find and delete 0-byte files recursively in a folder in Windows<\/a><\/em><\/p>\n<p>Let&#8217;s start with a neat GUI tool, followed by native command-line and scripting methods.<\/p>\n<h3><a id=\"red\"><\/a>1. Remove empty folders using the &#8220;Find Empty Files-n-Folders&#8221; utility<\/h3>\n<p>Find Empty Files-n-Folders is an excellent tool that can find and delete empty files (0-byte) and empty folders recursively under a folder tree.<\/p>\n<ol>\n<li>Download <a href=\"https:\/\/www.ashisoft.com\/find-empty-folders.htm\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">Find Empty Files-n-Folders<\/a> (600KB installer) from Ashisoft.com.<\/li>\n<li>Select the folder and click Scan Now.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9425\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/04\/find-empty-files-folders-1.png\" alt=\"remove empty folders in windows\" width=\"750\" height=\"523\" \/><br \/>\nThe tool will list empty files and folders in separate tabs.<\/li>\n<li>Click <strong>Mark all Folders<\/strong> and then click <strong>Delete Folders<\/strong>.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9424\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/04\/find-empty-files-folders-2.png\" alt=\"remove empty folders in windows\" width=\"750\" height=\"522\" \/><br \/>\n<em>Similarly, if you want to <a href=\"https:\/\/www.winhelponline.com\/blog\/find-and-delete-zero-byte-files-recursively-windows\/\" target=\"_blank\" rel=\"noopener noreferrer\">delete the 0-byte files<\/a> in the selected folder tree, click on the <strong>Empty Files<\/strong> tab.<\/em><\/li>\n<\/ol>\n<p>Ashisoft.com has other awesome tools that you can check out!<\/p>\n<div class=\"qt\">\nYou may also take a look at the &#8220;Empty Folder Cleaner&#8221; cleaner from 4-dots-software.com. It&#8217;s not a freeware, though. But a 30-day trial is available.<\/p>\n<pre>https:\/\/www.4dots-software.com\/emptyfoldercleaner\/<\/pre>\n<\/div>\n<hr \/>\n<h3><a id=\"rd\"><\/a>2. Remove empty folders using &#8220;for&#8221; and &#8220;rd&#8221; commands<\/h3>\n<p>You can use the Command Prompt internal commands <code><em>for<\/em><\/code> and <code><em>rd<\/em><\/code> to enumerate the list of folders and delete the empty ones.<\/p>\n<ol>\n<li>Press &amp; hold the <kbd>Shift<\/kbd> key, right-click on a folder and click <strong>Open command window here<\/strong>. This opens Command Prompt at the current folder location, which can also verify in the console.\n<div class=\"newline\"><em><strong>Note:<\/strong> You must make sure that you run the following command from the exact parent folder path where you need to find and remove empty sub-folders.<\/em><\/div>\n<\/li>\n<li>Once you&#8217;re in the desired directory in the Command Prompt, run this command-line:\n<pre>for \/f \"delims=\" %i in ('dir \/s \/b \/ad ^| sort \/r') do rd \"%i\" 2&gt;NUL\r\n(or)\r\nfor \/f \"usebackq delims=\" %i in (`\"dir \/s \/b \/ad | sort \/r\"`) do rd \"%i\" 2&gt;NUL<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8777\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/04\/robocopy-delete-empty-folder-for-command.png\" alt=\"remove empty folders using for and rd - batch command\" width=\"820\" height=\"74\" srcset=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/04\/robocopy-delete-empty-folder-for-command.png 820w, https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/04\/robocopy-delete-empty-folder-for-command-768x69.png 768w\" sizes=\"auto, (max-width: 820px) 100vw, 820px\" \/><\/p>\n<p>This deletes all the empty directories across sub-directories from the base folder path, including nested empty folders.<\/p>\n<p><em>If you&#8217;re going to use the above command in a batch file, then replace <code>%i<\/code> with <code>%%i<\/code>.<\/em><\/li>\n<\/ol>\n<p><strong><img loading=\"lazy\" decoding=\"async\" class=\"alignleft wp-image-18386\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2020\/09\/warning.png\" alt=\"warning caution icon\" width=\"32\" height=\"32\" \/>Important:<\/strong> The above command <strong>won&#8217;t delete<\/strong> folders with foreign characters &#8212; e.g.,\u00a0 \u870d\u7a42. You may want to check out <a href=\"#delempty\">DelEmpty.exe<\/a> (covered in this article) or other methods to delete folders with Unicode characters.<\/p>\n<p><em>The above command-line is courtesy of Raymond Chen of Microsoft, via his blog <a href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=22703\" target=\"_blank\" rel=\"noopener noreferrer\">The Old New Thing<\/a>. In this post, Raymond&#8217;s command-line has been slightly modified so that it also deletes folder names containing space(s).<\/em><\/p>\n<div class=\"qt\">\n<h4>How does the command work<\/h4>\n<p>The above command lists all the sub-directories (recursively) in the current base path and sorts the list (<code>sort \/r<\/code>) in reverse order. The reverse order sort is to make sure that the enumeration is done bottom-up. This is important for deleting empty directories, as you have to remove the subdirectories before removing the parent.<\/p>\n<p>Then it attempts to remove the list of directories (in reverse sort order) using the <code>RD<\/code> command. If a directory is not empty, it proceeds on to the next directory and so on. The <code>2&gt;NUL<\/code> command ensures that the &#8220;directory not empty&#8221; <a href=\"https:\/\/www.winhelponline.com\/blog\/copy-command-prompt-output-clipboard-save-file\/\">output text<\/a> is suppressed.<\/p>\n<\/div>\n<p>The only disadvantage of the above method is that it&#8217;s not helpful if you want to find empty folders without deleting them. If you want to find the list of empty folders, use the command-line in the paragraph below, or follow any other method described in this article.<\/p>\n<h4>Find empty folders, but don&#8217;t delete<\/h4>\n<p>To only find the empty folders without deleting them, use this command-line syntax:<\/p>\n<pre>for \/r \"D:\\uploads\\2019\" \/d %F in (.) do @dir \/b \"%F\" | findstr \"^\" &gt;nul || echo %~fF<\/pre>\n<p>It shows you the output containing the list of empty directories.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-20149\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/04\/empty-folders-list-command-prompt.png\" alt=\"list of empty folders - command line \" width=\"699\" height=\"425\" \/><\/p>\n<p>Let&#8217;s say you have empty nested folders like this:<\/p>\n<pre>C:\\1\r\n\u2514\u2500\u2500\u25002\r\n    \u2514\u2500\u2500\u25003\r\n        \u2514\u2500\u2500\u25004<\/pre>\n<p>Running the above command lists only the deep most empty folder \u2192 <code>4<\/code>. Technically, it&#8217;s correct because a folder can&#8217;t be considered empty if a sub-folder or a file exists in it.<\/p>\n<hr \/>\n<h3><a id=\"robocopy\"><\/a>3. Find and remove empty folders using Robocopy<\/h3>\n<p>Robocopy is a powerful built-in file copy tool that has a lot of advanced features. We&#8217;ve covered Robocopy in the article <a href=\"https:\/\/www.winhelponline.com\/blog\/compare-two-directories-files-find-differences\/\">Compare the Contents of Two Folders in Windows<\/a>.<\/p>\n<p><em>Let&#8217;s assume you have a folder named <code>cars<\/code> , which contains several sub-folders, of which some are empty. We&#8217;re going to delete the empty ones using Robocopy.<\/em><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-6419\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2018\/08\/hand.png\" alt=\"hand point icon\" width=\"49\" height=\"27\" \/>The <strong>trick<\/strong> here is to use the Robocopy move command, passing the exact same folder path for both &#8220;source&#8221; as well as &#8220;destination.&#8221;<\/p>\n<ol>\n<li>Open a Command Prompt window.<\/li>\n<li>Type the following command and press <kbd>ENTER<\/kbd>:\n<pre>robocopy \"d:\\automobile rates\\cars\" \"d:\\automobile rates\\cars\" \/S \/move<\/pre>\n<p><em>The <strong>most important<\/strong> thing to note here is that the <strong>source<\/strong> and <strong>destination<\/strong> paths are (deliberately) the same. The <code>\/S<\/code> parameter instructs Robocopy not to move empty folders to the &#8220;destination&#8221; path. As we&#8217;ve mentioned the same paths for source and destination, Robocopy will delete the empty folders due to the <code>\/S<\/code> switch.<\/em><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8776\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/04\/robocopy-remove-empty-folders-1.png\" alt=\"robocopy remove empty folders\" width=\"700\" height=\"561\" \/><\/li>\n<\/ol>\n<p>The empty folders in the chosen path are now cleared.<\/p>\n<div class=\"qt\">\n<h4>Want to find empty folders but not delete them?<\/h4>\n<p>You can use the <code>\/L<\/code> (list-only) command-line argument with Robocopy so that it only carries out a dry-run instead of performing the actual copy\/move operation.<\/p>\n<p><code>\/L<\/code> :: List only &#8211; don&#8217;t copy, timestamp, or delete any files.<br \/>\n<code>\/MOVE<\/code> :: MOVE files AND dirs (delete from source after copying).<br \/>\n<code>\/S<\/code> :: copy Subdirectories, but not empty ones.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8775\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/04\/robocopy-remove-empty-folders-list-only.png\" alt=\"robocopy delete empty folders - list -dryrun\" width=\"700\" height=\"562\" \/><\/p>\n<p>You can see the number of files in a column hear the folder path. The <code>0<\/code>s mean that those folders have no files.<\/p>\n<\/div>\n<p>Let&#8217;s put this command to a real test!<\/p>\n<p>My <code>%APPDATA%<\/code> folder is full of empty folders added by obsolete programs.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8773\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/04\/robocopy-appdata-folder.png\" alt=\"appdata roaming folder contents\" width=\"701\" height=\"481\" \/><\/p>\n<p>Before the cleanup, the <strong>Appdata\\Roaming<\/strong> folder had 681 folders, as seen in the folder properties.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8781\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/04\/robocopy-delete-empty-folder-before-1.png\" alt=\"remove empty folders - before\" width=\"363\" height=\"499\" \/><\/p>\n<p>I opened the Command Prompt and ran the following command:<\/p>\n<pre>robocopy \"%appdata%\" \"%appdata%\" \/S \/MOVE<\/pre>\n<p><em>Note: %appdata% environment variable translates to <code>C:\\Users\\{username}\\AppData\\Roaming<\/code> folder. You can use the full folder path or the equivalent environment variable with Robocopy. Either is fine.<\/em><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8778\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/04\/robocopy-delete-empty-folder-appdata.png\" alt=\"robocopy remove empty folders - appdata roaming\" width=\"681\" height=\"387\" \/><\/p>\n<p>It has successfully removed <strong>94<\/strong> empty folders in my <code>%APPDATA%<\/code> folder and sub-folders.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8780\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/04\/robocopy-delete-empty-folder-after-1.png\" alt=\"remove empty folders - after\" width=\"363\" height=\"499\" \/><\/p>\n<p><em><strong>Editor&#8217;s note:<\/strong> In the command-line output below the statistics section, the following error appeared:<\/em><\/p>\n<div class=\"err\">&#8220;ERROR 32 (0x00000020) Deleting Source Directory C:\\Users\\ramesh\\AppData\\Roaming\\<br \/>\nThe process cannot access the file because it is being used by another process.&#8221;<\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8779\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/04\/robocopy-delete-empty-folder-appdata-results.png\" alt=\"robocopy remove empty folders - error\" width=\"681\" height=\"387\" \/><\/p>\n<p><em>Because we&#8217;ve instructed Robocopy to move (<code>\/MOVE<\/code>) the %APPDATA% directory, the tool was trying to clean up the &#8220;source&#8221; folder after &#8220;moving&#8221; it to the destination. It couldn&#8217;t, as %APPDATA% is a special folder. The error doesn&#8217;t occur when used a directory path that&#8217;s not a special folder. As everything went on fine, I simply ignored the (trivial) error.<\/em><\/p>\n<hr \/>\n<h3><a id=\"powershell\"><\/a>4. Find and Remove empty folders using PowerShell<\/h3>\n<p>The following PowerShell command-line deletes empty folders located under the specified base folder recursively.<\/p>\n<ol>\n<li>Start PowerShell and type the following command:\n<pre>(gci \"folderpath\" -r | ? {$_.PSIsContainer -eq $True}) | ?{$_.GetFileSystemInfos().Count -eq 0} | remove-item<\/pre>\n<p><em>Replace &#8220;folderpath&#8221; with the base folder location. For example, I&#8217;m specifying the <strong>Roaming<\/strong> folder here:<\/em><\/p>\n<pre>(gci \"C:\\Users\\ramesh\\AppData\\Roaming\" -r | ? {$_.PSIsContainer -eq $True}) | ?{$_.GetFileSystemInfos().Count -eq 0} | remove-item<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8783\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/04\/powershell-delete-empty-folders.png\" alt=\"powershell remove empty folders recursively\" width=\"979\" height=\"88\" srcset=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/04\/powershell-delete-empty-folders.png 979w, https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/04\/powershell-delete-empty-folders-768x69.png 768w\" sizes=\"auto, (max-width: 979px) 100vw, 979px\" \/><\/p>\n<p>This deletes all the empty sub-folders under my <code>%appdata%<\/code> folder recursively and doesn&#8217;t show any output unless it encounters any error(s).<\/li>\n<\/ol>\n<p>Note that the above PowerShell command clears only the last level of the empty nested folder. For example, let&#8217;s say you have empty nested folders like this:<\/p>\n<pre>C:\\1\r\n\u2514\u2500\u2500\u25002\r\n    \u2514\u2500\u2500\u25003\r\n        \u2514\u2500\u2500\u25004<\/pre>\n<p>Running the above command clears the deep most empty folder \u2192 <code>4<\/code>. Rerunning the script will clear another level of a nested folder (<code>3<\/code>), and so forth.<\/p>\n<p><em>You can use the PowerShell script at <a href=\"https:\/\/www.powershelladmin.com\/wiki\/PowerShell_script_to_recursively_delete_empty_folders\" target=\"_blank\" rel=\"noopener noreferrer\">Svendsen Tech PowerShell Wiki<\/a> to work with nested folders.<\/em><\/p>\n<p><em>Alternately, you can use the next method, a <a href=\"#script\">Windows Scripting<\/a> solution, to clear all empty folders, including nested ones, recursively.<\/em><\/p>\n<div class=\"qt\">\n<h4>Find empty folders, but don&#8217;t want to delete them?<\/h4>\n<p>Want to get the list of empty folders, but don&#8217;t want to delete them? Use this command-line example instead:<\/p>\n<pre>(gci \"C:\\Users\\ramesh\\AppData\\Roaming\" -r | ? {$_.PSIsContainer -eq $True}) | ?{$_.GetFileSystemInfos().Count -eq 0} | select FullName | Out-GridView<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8784\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/04\/powershell-find-empty-folders-command.png\" alt=\"powershell remove empty folders recursively\" width=\"979\" height=\"98\" srcset=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/04\/powershell-find-empty-folders-command.png 979w, https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/04\/powershell-find-empty-folders-command-768x77.png 768w\" sizes=\"auto, (max-width: 979px) 100vw, 979px\" \/><\/p>\n<p>The command outputs the list of empty folders with full paths to a grid view control.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8785\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/04\/powershell-find-empty-folders-output.png\" alt=\"powershell find empty folders list output grid view\" width=\"716\" height=\"452\" \/><\/p>\n<p><em><strong>Tip:<\/strong> In the grid view, you can select all and copy the selection by pressing <kbd>Ctrl<\/kbd> + <kbd>C<\/kbd><\/em><\/p>\n<p>It&#8217;s a good idea to preview the list before running the command to delete the folders.<\/p>\n<\/div>\n<hr \/>\n<h3><a id=\"script\"><\/a>5. Find and Remove empty folders using Windows Scripting<\/h3>\n<p>Microsoft employee <a href=\"https:\/\/blogs.msdn.microsoft.com\/jjameson\/2009\/11\/03\/deleting-empty-folders\/\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">Jeremy Jameson<\/a> wrote a VBScript that deletes empty folders recursively. I&#8217;ve added more lines in the script to force delete empty read-only directories, output the aggregated list of empty folders. It also outputs the list of empty folders that could not be deleted, along with the corresponding error description.<\/p>\n<p>The script is capable of deleting nested empty directories across sub-folders.<\/p>\n<p><script src=\"https:\/\/gist.github.com\/winhelponline\/94f0297235914e4068c20af96e5b31ba.js?file=del_empty_folders.vbs\"><\/script><\/p>\n<p><noscript><\/p>\n<pre><code>\r\n'Deletes empty folders recursively in Windows\r\n'https:\/\/www.winhelponline.com\/blog\/find-and-delete-empty-folders-windows\/\r\n\r\nOption Explicit\r\n\r\nIf (WScript.Arguments.Count <> 1) Then\r\n   WScript.Echo(\"Usage: cscript DeleteEmptyFolders.vbs {path}\")\r\n   WScript.Quit(1)\r\nEnd If\r\n\r\nDim strPath : strPath = WScript.Arguments(0)\r\nDim fso : Set fso = CreateObject(\"Scripting.FileSystemObject\")\r\nDim objFolder : Set objFolder = fso.GetFolder(strPath)\r\nDim sDelList, sDelErr, sFolderPath\r\nDim iCnt\r\niCnt = 0\r\n\r\nDeleteEmptyFolders objFolder\r\n\r\nSub DeleteEmptyFolders(folder)\r\n   Dim subfolder\r\n\r\n   On Error Resume Next\r\n   'Skip errors when accessing Junctions etc.\r\n   For Each subfolder In folder.SubFolders\r\n      DeleteEmptyFolders subfolder\r\n   Next\r\n   On Error Goto 0\r\n   \r\n   If folder.SubFolders.Count = 0 And folder.Files.Count = 0 Then\r\n      sFolderPath = folder.Path\r\n      On Error Resume Next\r\n      fso.DeleteFolder folder.Path, True\r\n      If Err.number <> 0 Then\r\n         sDelErr = sDelErr & Err.number & \": \" & Err.description & _\r\n         \tvbCrLf & sFolderPath & vbCrLf & vbCrLf\r\n      Else\r\n         sDelList = sDelList & vbCrLf & sFolderPath\r\n\t iCnt  = iCnt + 1\r\n      End If\t\t\r\n      On Error Goto 0\r\n   End If\t\r\nEnd Sub\r\n\r\nIf sDelList = \"\" And sDelErr = \"\" Then\r\n   WScript.Echo \"No Empty folders found under the \" & _\r\n\t\"\"\"\" & strPath & \"\"\"\" & \" tree\"\r\n   WScript.Quit\r\nEnd If\r\n\r\nIf sDelList <> \"\" then sDelList = \"List of empty folders deleted\" & vbCrLf _\r\n   & String(38,\"-\") & vbCrLf & sDelList & vbCrLf & _\r\n\tvbCrLf  & \"Total: \" & iCnt & \" folders deleted.\"\r\n\r\nIf sDelErr <> \"\" then sDelErr = \"These folders could not be deleted\" & _\r\n   vbCrLf & String(45,\"-\") & vbCrLf & sDelErr\r\n\r\nWScript.Echo sDelList & vbCrLf & vbCrLf & sDelErr\r\n<\/code><\/pre>\n<p><\/noscript><\/p>\n<ul>\n<li>Download <a href=\"https:\/\/gist.github.com\/winhelponline\/94f0297235914e4068c20af96e5b31ba\" target=\"_blank\" rel=\"noopener noreferrer\">del_empty_folders.vbs<\/a><\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-full wp-image-9273\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/04\/del-empty-folders-script-6.png\" alt=\"\" width=\"278\" height=\"123\" \/><em>Optionally, you may rename the script file accordingly, let&#8217;s say <strong>delempty.vbs<\/strong>, and move it to the <code>C:\\Windows<\/code> folder.<\/em><\/p>\n<p>You can run the script using two ways:<\/p>\n<p><strong>via Command Prompt, by running:<\/strong><\/p>\n<pre>cscript.exe delempty.vbs \"folder_path\"<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9270\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/04\/del-empty-folders-script-4.png\" alt=\"find and remove empty folders\" width=\"700\" height=\"337\" \/><\/p>\n<p><strong>via GUI, by running:<\/strong><\/p>\n<pre>wscript.exe delempty.vbs \"folder_path\"<\/pre>\n<p><strong>via the Send To menu<\/strong><\/p>\n<p>You can create a shortcut to the script in <a href=\"https:\/\/www.winhelponline.com\/blog\/shell-commands-to-access-the-special-folders\/\">your SendTo folder<\/a>\u00a0and name it <strong>Delete Empty Folders<\/strong>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9268\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/04\/del-empty-folders-script-1.png\" alt=\"remove empty folders\" width=\"580\" height=\"284\" \/><\/p>\n<p>Then, right-click on a folder where you want to delete empty sub-folders recursively \u2192 click <strong>Send To<\/strong> \u2192 click <strong>Delete Empty Folders<\/strong> in the Send To menu.<\/p>\n<p>You&#8217;ll see the list of empty folders deleted and the total, and folders that couldn&#8217;t be deleted with the respective error codes displayed.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9272\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/04\/del-empty-folders-script-5.png\" alt=\"find and delete empty folders - vbscript\" width=\"413\" height=\"679\" \/><\/p>\n<hr \/>\n<h3><a id=\"delempty\"><\/a>6. Find and Remove empty folders using DelEmpty.exe<\/h3>\n<p><a href=\"http:\/\/www.intelliadmin.com\/index.php\/downloads\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">DelEmpty.exe<\/a> is a console tool from IntelliAdmin that can delete empty directories recursively. This program can also swiftly delete the empty <a href=\"https:\/\/www.winhelponline.com\/blog\/find-and-delete-zero-byte-files-recursively-windows\/\">0-byte files<\/a> recursively.<\/p>\n<p>The following is the command-line syntax for the program:<\/p>\n<pre>DelEmpty.exe OPTIONS [PATH]<\/pre>\n<table style=\"border-collapse: collapse; width: 60%;\">\n<tbody>\n<tr>\n<td style=\"width: 25%; text-align: center;\"><strong>Argument<\/strong><\/td>\n<td style=\"width: 75%; text-align: center;\"><strong>Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 25%; text-align: center;\">-f<\/td>\n<td style=\"width: 75%;\">Delete empty (0-byte) files<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 25%; text-align: center;\">-d<\/td>\n<td style=\"width: 75%;\">Delete empty directories<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 25%; text-align: center;\">-v<\/td>\n<td style=\"width: 75%;\">Verbose mode<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 25%; text-align: center;\">-c<\/td>\n<td style=\"width: 75%;\">Confirm mode (Shows what was deleted)<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 25%; text-align: center;\">-s<\/td>\n<td style=\"width: 75%;\">Include sub-directories (traverse subfolders)<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 25%; text-align: center;\">-l<\/td>\n<td style=\"width: 75%;\">List what would be deleted (<strong>will not delete<\/strong>)<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 25%; text-align: center;\">-y<\/td>\n<td style=\"width: 75%;\">Delete without (y\/n) prompt<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Example 1:<\/strong> To <strong>list<\/strong> the empty folders under the Mozilla directory under AppData, I used the following command-line:<\/p>\n<pre>DelEmpty.exe \"%AppData%\\Mozilla\" -d -c -s -y -l<\/pre>\n<p>The above command shows the list of empty folders, but will not delete them since the <code>-l<\/code> (<strong>list only<\/strong>) switch is used.<\/p>\n<p><em>For folder names containing space(s) &#8212; e.g., <code>Mozilla Firefox<\/code>, be sure to include the double-quotes around the path.<\/em><\/p>\n<p><strong>Example 2:<\/strong> To <strong>delete<\/strong> the empty folders under the <code>Mozilla directory<\/code> under <code>%AppData%<\/code>, I run the same command-line but without the <code>-l<\/code> switch:<\/p>\n<pre>DelEmpty.exe \"%AppData%\\Mozilla\" -d -c -s -y<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-20253\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/04\/delempty-1.png\" alt=\"delete empty directories recursively\" width=\"750\" height=\"409\" \/><\/p>\n<p>The program traverses through every subfolder and deletes the empty folders. Nested empty folders are removed too. For example, if you were looking to remove empty directories from this structure:<\/p>\n<pre>C:\\Folder1\\Folder2\\EmptyFolder1\r\nC:\\Folder1\\Folder2\\EmptyFolder2<\/pre>\n<p>After the <code>EmptyFolder1<\/code> and <code>EmptyFolder2<\/code> folders are removed, Folder 2 is empty as well &#8212; and it will also be removed. Also, <code>DelEmpty.exe<\/code> is capable of removing folders with unicode\/foreign characters as well &#8212; e.g., \u870d\u7a42<\/p>\n<hr \/>\n<h3><a id=\"nirsoft\"><\/a>7. Find and Remove empty folders Using SearchMyFiles utility<\/h3>\n<p><strong>SearchMyFiles<\/strong> is a utility from Nirsoft.net that&#8217;s a good alternative to the standard Windows Search feature. <a href=\"https:\/\/www.nirsoft.net\/utils\/search_my_files.html\" target=\"_blank\" rel=\"noopener nofollow\">SearchMyFiles<\/a> can be used to quickly find and\/or delete empty directories in Windows.<\/p>\n<ol>\n<li>In the <strong>Search Options<\/strong> dialog of the SearchMyFiles utility, select <strong>Summary Mode<\/strong>.<br \/>\n<em>(The &#8216;Summary Mode&#8217; feature displays a general summary of all scanned folders, instead of the files list. For every folder, the following summary information is displayed: Total size of all files, total files count, and other information.)<br \/>\n<\/em><\/li>\n<li>Select &#8220;Only folders with zero files and subfolders&#8221; in the drop-down list box.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-25053\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/04\/searchmyfiles_find_empty_folders_1.png\" alt=\"find and delete empty directories using searchmyfiles utility\" width=\"639\" height=\"623\" \/><\/li>\n<li>Type the base folder path(s) to find the empty folders. Add a comma as a separator if you plan to search more than one base folder.<\/li>\n<li>Once done, click the <strong>Start Search<\/strong> button.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-25052\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/04\/searchmyfiles_find_empty_folders_2.png\" alt=\"find and delete empty directories using searchmyfiles utility\" width=\"698\" height=\"423\" \/><\/li>\n<li>You&#8217;ll find the list of empty folders under the specified base folder. If you wish to delete them, select the items in the listing, right-click and select <strong>Delete Selected Empty Folders<\/strong>. That&#8217;s it. It deletes the (selected) empty folders from your computer.<\/li>\n<\/ol>\n<p><em>If you know of any other methods to remove empty folders in Windows, let&#8217;s know that in the comments section below.<\/em><\/p>\n<p>Last reviewed on 05-July-2023.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Over time, hundreds of empty folders and junk files may take up your hard disk. While the junk files occupy disk space and can be cleaned up using Disk Cleanup or Storage settings, the empty directories remain. The empty folders don&#8217;t take up disk space, but to organize your data better, you may want to &#8230; <a title=\"How to Find and Remove Empty Folders in Windows\" class=\"read-more\" href=\"https:\/\/www.winhelponline.com\/blog\/find-and-delete-empty-folders-windows\/\" aria-label=\"Read more about How to Find and Remove Empty Folders in Windows\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[6,7],"tags":[106,396,733,480],"class_list":["post-8771","post","type-post","status-publish","format-standard","hentry","category-utilities","category-windows","tag-command-prompt","tag-powershell","tag-robocopy","tag-scripts"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":10509,"url":"https:\/\/www.winhelponline.com\/blog\/how-to-copy-folder-structure-without-copying-files\/","url_meta":{"origin":8771,"position":0},"title":"Copy Folder Structure without Copying Files in Windows","author":"Ramesh","date":"July 28, 2019","format":false,"excerpt":"There are situations where you want to copy a folder structure without copying the files in that folder and sub-folders. For instance, you may want to replicate the directory structure of your expenses or accounting folders in order to organize them year-wise. I have the following directory structure to store\u2026","rel":"","context":"In &quot;Windows&quot;","block_context":{"text":"Windows","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/"},"img":{"alt_text":"directory list structure batch file powershell","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/07\/dir-list-to-bat-powershell-replicate.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":9357,"url":"https:\/\/www.winhelponline.com\/blog\/find-and-delete-zero-byte-files-recursively-windows\/","url_meta":{"origin":8771,"position":1},"title":"How to Delete Empty files (0 byte) in Windows?","author":"Ramesh","date":"May 18, 2019","format":false,"excerpt":"Some applications create empty 0-byte files in their data folders and fail to clear them up. Over time, if you see many zero-byte files in a folder hierarchy, here are some methods to find all those 0-byte files and delete them. Find and\/or delete empty (0 byte) files in Windows:\u2026","rel":"","context":"In &quot;Windows&quot;","block_context":{"text":"Windows","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/"},"img":{"alt_text":"delete empty files recursively","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/05\/delempty-0-byte-files-1.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/05\/delempty-0-byte-files-1.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/05\/delempty-0-byte-files-1.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/05\/delempty-0-byte-files-1.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":6018,"url":"https:\/\/www.winhelponline.com\/blog\/delete-unused-files-older-than-x-days-windows\/","url_meta":{"origin":8771,"position":2},"title":"How to Delete Files Older than N Days Automatically in Windows","author":"Ramesh","date":"December 11, 2017","format":false,"excerpt":"Windows 10 has built-in features to free up space by deleting old files in the %temp% directory and Downloads folder. Windows 10 Settings has an option (\"Storage\") which automatically clears temporary files your apps are not using, files in the Downloads that haven't been modified in the last x days,\u2026","rel":"","context":"In &quot;Windows&quot;","block_context":{"text":"Windows","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/"},"img":{"alt_text":"windows 10 storage settings cleanup options","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/11\/storage-settings-cleanup-options.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/11\/storage-settings-cleanup-options.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/11\/storage-settings-cleanup-options.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":1386,"url":"https:\/\/www.winhelponline.com\/blog\/blue-double-arrow-icon-files-folders-windows-10\/","url_meta":{"origin":8771,"position":3},"title":"What is the Two Blue Arrows Icon on Folders in Windows 10 and How to Remove it?","author":"Ramesh","date":"December 26, 2015","format":false,"excerpt":"After installing Windows 10, you may notice that some of your files and folders show up with a double blue arrows icon at the top. This double blue arrows overlay icon is seen if the files and folders are compressed (NTFS compression), and there is nothing to worry about. This\u2026","rel":"","context":"In &quot;Windows 10&quot;","block_context":{"text":"Windows 10","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/windows-10\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2015\/12\/windows-compress-blue-arrow.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2015\/12\/windows-compress-blue-arrow.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2015\/12\/windows-compress-blue-arrow.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2015\/12\/windows-compress-blue-arrow.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":80841,"url":"https:\/\/www.winhelponline.com\/blog\/delete-worldofwarships-folder-windowsapps\/","url_meta":{"origin":8771,"position":4},"title":"How to Delete the WorldOfWarships folders from WindowsApps","author":"Ramesh","date":"May 21, 2026","format":false,"excerpt":"When you install World of Warships (WoW) via the Microsoft Store, it often occupies significant space within the protected C:\\Program Files\\WindowsApps folder. The game can require 60\u201390 GB of storage after installation, and sometimes even more during updates. In some cases, the older versions are not removed during the WoW\u2026","rel":"","context":"In &quot;Windows 10&quot;","block_context":{"text":"Windows 10","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/windows-10\/"},"img":{"alt_text":"worldofwarships folders in WindowsApps","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2026\/05\/worldofwarships-folders-2.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2026\/05\/worldofwarships-folders-2.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2026\/05\/worldofwarships-folders-2.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2026\/05\/worldofwarships-folders-2.jpg?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":3766,"url":"https:\/\/www.winhelponline.com\/blog\/compare-two-directories-files-find-differences\/","url_meta":{"origin":8771,"position":5},"title":"How to Compare the Contents of Two Folders and Synchronize them","author":"Ramesh","date":"August 10, 2016","format":false,"excerpt":"Traditionally, Windows users have employed XCOPY or SyncToy to mirror copy a certain directory to a different location. If you're using Microsoft SyncToy, especially on Windows 10 or 11, it's possible that sometimes the files or folders may be missing in the destination, or the destination folder has extra files\u2026","rel":"","context":"In &quot;Utilities&quot;","block_context":{"text":"Utilities","link":"https:\/\/www.winhelponline.com\/blog\/category\/utilities\/"},"img":{"alt_text":"syncfolders - compare and sync files - task scheduler","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/08\/syncfolders-scheduler.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/08\/syncfolders-scheduler.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/08\/syncfolders-scheduler.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/posts\/8771","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/comments?post=8771"}],"version-history":[{"count":0,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/posts\/8771\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/media?parent=8771"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/categories?post=8771"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/tags?post=8771"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}