* Wu, Yue on Thursday, September 24, 2009 at 09:24:35 +0800
> On Wed, Sep 23, 2009 at 09:03:09AM -0500, Kyle Wheeler wrote:
>> On Wednesday, September 23 at 09:45 PM, quoth Wu, Yue:
>>> The logic I need is:
>>> 
>>>   if maildir A has no mails(new/ tmp/ cur/ are empty)
>>>       rm -r A
>>>   endif
>> 
>> Ahh. How about:
>> 
>>     if [ $(find A -type f | wc -l) -eq 0 ] ; then
>>         rm -r A
  
           rm -r $A

>>     fi
> 
> Thanks for all replies, mutt uses its own maildir so I have no issue about the
> two apps read/write the same maildirs at one time.
> 
> I don't know sh, and I've tried the following sh script, but it doesn't work:
> 
> #!/bin/sh
> 
> DIR="~/temp/mails/*"
> 
> for d in ${DIR}; do
>        if [ $(find d -type f | wc -l) -eq 0 ] ; then
>                rm -r d
 
                 rm -r $d

But I would be careful with rm while developing the script, perhaps do a

                 echo $d

first, to see what would be removed.
 
>        fi
> done

I also think this does not work with a nested hierarchy. Try this
for a simple nested hierarchy:


mailhier="~/temp/mails"

for md in `find $mailhier -type d \( -name cur -o -name new -o -name tmp 
-execdir pwd \; \) -prune`; do
    if [ `find "$md" -type f | wc -l` -eq 0 ]; then
        echo "$md"
        # rm -r "$md"
    fi
done


c
-- 
\black\trash movie    _C O W B O Y_  _C A N O E_  _C O M A_
                     Ein deutscher Western/A German Western

         --->> http://www.blacktrash.org/underdogma/ccc.php

Reply via email to