Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Tip of the day: prune empty directory hierarchies



In case anybody ever wanted this and there isn't a standard solution I
don't know about...

pws


# Prune empty directory hierarchies below the current directory.  That's
# a hierarchy where everything underneath is itself a directory.
#
# The first search is slow, but subsequently it simply goes up one
# directory each time so it's much faster.

local -aU dirs

dirs=(**/*(ND/^F))
while (( ${#dirs} )); do
  rmdir $dirs || return
  # print Pruhed ${#dirs} directories...
  dirs=(${^dirs:h}(ND/^F))
done



Messages sorted by: Reverse Date, Date, Thread, Author