I've been looking for a quick and easy way to remove empty maildir folders, I was going write a short shell script but while I was thinking about this I came across 'rmdir -p'. Thinking that this was sort of equivalent to 'mkdir -p' I tried to use it and it acts very strangely.
If you have an empty maildir folder called (for example) mdf then "rmdir -p mdf" simply gives the error "rmdir: mdf: Directory not empty", it doesn't recurse down into the directory and find that the sub-directories are empty and them remove the lot.
If you give the command "rmdir -p mdf/*" then it gives the error "rmdir: mdf: Directory not empty" twice but does actually remove the whole maildir folder. What's happening is that it removes each of the 'cur', 'tmp' and 'new' sub-directories of 'mdf' but only when it removes the last one does it also remove the parent directory.
I can think of no practical use for this command! :-)
It's no good for my requirement because it might remove some of the maildir sub-directories then find the next one wasn't empty and leave a partial maildir folder.
I think I'm back to my script for doing it.
Hi Chris
On Friday 04 May 2007 10:33, Chris G wrote:
If you give the command "rmdir -p mdf/*" then it gives the error "rmdir: mdf: Directory not empty" twice but does actually remove the whole maildir folder. What's happening is that it removes each of the 'cur', 'tmp' and 'new' sub-directories of 'mdf' but only when it removes the last one does it also remove the parent directory.
From the man page, we see that:
-p, --parents Remove DIRECTORY and its ancestors. E.g., ‘rmdir -p a/b/c’ is similar to ‘rmdir a/b/c a/b a’.
So, assuming a mdf/cur mdf/new, and mdf/old layout, `rmdir -p mdf/*` would indeed complain when it removes cur & new. When it removes old, mdf would then be empty, so that too would be deleted..
Regards, Paul.
On Fri, May 04, 2007 at 10:48:48AM +0100, Paul wrote:
Hi Chris
On Friday 04 May 2007 10:33, Chris G wrote:
If you give the command "rmdir -p mdf/*" then it gives the error "rmdir: mdf: Directory not empty" twice but does actually remove the whole maildir folder. What's happening is that it removes each of the 'cur', 'tmp' and 'new' sub-directories of 'mdf' but only when it removes the last one does it also remove the parent directory.
From the man page, we see that:
-p, --parents Remove DIRECTORY and its ancestors. E.g., ???rmdir -p a/b/c??? is similar to ???rmdir a/b/c a/b a???.
So, assuming a mdf/cur mdf/new, and mdf/old layout, `rmdir -p mdf/*` would indeed complain when it removes cur & new. When it removes old, mdf would then be empty, so that too would be deleted..
Yes, I thought I'd said that with my last sentence above. However it still seems that it's close to useless. :-)