🐛 rmdir-empty: directory might have been removed in the first level round

This commit is contained in:
neingeist 2026-04-19 18:58:23 +02:00
parent 3b21559014
commit 4ae427ef45

View file

@ -9,9 +9,18 @@ rmdir_empty() {
# do the first level directories first
for maxdepth_opt in "-maxdepth 1" ""; do
find "$@" -depth -mindepth 1 $maxdepth_opt \
for d in "$@"; do
# directory might have been removed in the first level round
if [ -z "$max_depth_opt" -a ! -e "$d" ]; then
continue
fi
find "$d" -depth $maxdepth_opt \
-path "." -prune -or \
-type d -empty -exec rmdir -v {} \;
done
done
}
rmdir_empty "$@"