Skip to content

Instantly share code, notes, and snippets.

@neps-in
Created December 19, 2021 17:35
Show Gist options
  • Select an option

  • Save neps-in/d69d128c2d863f654ae980a9bddc8016 to your computer and use it in GitHub Desktop.

Select an option

Save neps-in/d69d128c2d863f654ae980a9bddc8016 to your computer and use it in GitHub Desktop.
rdempty.cmd Delete empty directory
for /f "usebackq" %%d in (`"dir /ad/b/s | sort /R"`) do rd "%%d"
@neps-in

neps-in commented Dec 19, 2021

Copy link
Copy Markdown
Author

Explanation :
https://devblogs.microsoft.com/oldnewthing/20080417-00/?p=22703

This is the long-forgotten follow-up to Performing an operation in each subdirectory of a directory tree from batch. We’re using the same technique as in that article, but pumping the result through “| sort /R” to reverse the order of the enumeration so we enumerate the directories bottom-up rather than top-down. This is important for deleting empty directories because you have to remove the subdirectories before you remove the parent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment