Created
January 20, 2026 20:37
-
-
Save ghall89/2b9ab7ff8ab126ff46925c2a30d58cfc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Recursively delete empty folders starting from the current directory | |
| require 'find' | |
| require 'fileutils' | |
| root = '.' | |
| empty_dirs = [] | |
| Find.find(root) do |path| | |
| if File.directory?(path) | |
| next if path == root | |
| if Dir.entries(path).size <= 2 | |
| empty_dirs << path | |
| end | |
| end | |
| end | |
| empty_dirs.each do |dir| | |
| print("Deleting #{dir}\n") | |
| FileUtils.remove_dir(dir) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment