Abstract remove empty directories into function.