From 4ae427ef45019de59774ea2c941c8684c7de516f Mon Sep 17 00:00:00 2001 From: neingeist Date: Sun, 19 Apr 2026 18:58:23 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20rmdir-empty:=20directory=20might?= =?UTF-8?q?=20have=20been=20removed=20in=20the=20first=20level=20round?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rmdir-empty | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/rmdir-empty b/rmdir-empty index 0cc0db2..0f39ca9 100755 --- a/rmdir-empty +++ b/rmdir-empty @@ -9,8 +9,17 @@ rmdir_empty() { # do the first level directories first for maxdepth_opt in "-maxdepth 1" ""; do - find "$@" -depth -mindepth 1 $maxdepth_opt \ - -type d -empty -exec rmdir -v {} \; + 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 }