{"id":22703,"date":"2008-04-17T10:00:00","date_gmt":"2008-04-17T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2008\/04\/17\/one-line-batch-script-to-delete-empty-directories\/"},"modified":"2008-04-17T10:00:00","modified_gmt":"2008-04-17T10:00:00","slug":"one-line-batch-script-to-delete-empty-directories","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20080417-00\/?p=22703","title":{"rendered":"One-line batch script to delete empty directories"},"content":{"rendered":"<p>\n<a HREF=\"http:\/\/www.lockergnome.com\/nexus\/windows\/2007\/02\/20\/empty-folder-nuker-v120\/\">\nYou don&#8217;t need a whole 260KB program to do it<\/a>.\nThis batch file does the trick just fine:\n<\/p>\n<pre>\nfor \/f \"usebackq\" %%d in (`\"dir \/ad\/b\/s | sort \/R\"`) do rd \"%%d\"\n<\/pre>\n<p>\nI call it <code>rdempty.cmd<\/code>.\n<\/p>\n<p>\nThis is the long-forgotten follow-up to\n<a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2007\/05\/11\/2532913.aspx#2571579\">\nPerforming an operation in each subdirectory of a directory tree\nfrom batch<\/a>.\nWe&#8217;re using the same technique as in that article,\nbut pumping the result through &#8220;<code>| sort \/R<\/code>&#8221;\nto reverse the order of the enumeration so we enumerate\nthe directories bottom-up rather than top-down.\nThis is important for deleting empty directories\nbecause you have to remove the subdirectories before\nyou remove the parent.\n<\/p>\n<p>\n<b>Disclaimer<\/b>:\nI doubt anybody actually enjoys working with batch files,\nbut that doesn&#8217;t mean that tips on using it more effectively\naren&#8217;t valid.\nIf you would rather gouge your eyes out than use the confusing\ncommand prompt batch language,\nthen you are more than welcome to use\nthe scripting language of your choice instead.\nAt no point in this article am I saying that this is the only way\nor the best way to do it.\nBut it&#8217;s definitely smaller than a 260KB program.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You don&#8217;t need a whole 260KB program to do it. This batch file does the trick just fine: for \/f &#8220;usebackq&#8221; %%d in (`&#8221;dir \/ad\/b\/s | sort \/R&#8221;`) do rd &#8220;%%d&#8221; I call it rdempty.cmd. This is the long-forgotten follow-up to Performing an operation in each subdirectory of a directory tree from batch. We&#8217;re using [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[104],"class_list":["post-22703","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-tipssupport"],"acf":[],"blog_post_summary":"<p>You don&#8217;t need a whole 260KB program to do it. This batch file does the trick just fine: for \/f &#8220;usebackq&#8221; %%d in (`&#8221;dir \/ad\/b\/s | sort \/R&#8221;`) do rd &#8220;%%d&#8221; I call it rdempty.cmd. This is the long-forgotten follow-up to Performing an operation in each subdirectory of a directory tree from batch. We&#8217;re using [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/22703","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=22703"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/22703\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=22703"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=22703"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=22703"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}