Murdering Folders. In Ruby

My mp3 player tends to accumulate sub-folders in my podcast folder as my podcast app syncs with it and podcast episodes come and go. Rather than leave them unoccupied and unloved, I use this script to “tidy them up”. By killing them.


Dir['**/*'] \
	.select { |d| File.directory?(d) } \
	.select { |d| (Dir.entries(d) - %w[ . .. ]).empty? } \
	.each { |d| Dir.rmdir d }